<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK href="diff-s.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="nav-div.js"></script>
</head>
<body>
<div id="left" class="src">
<pre>
<a id='leftstart' tid='rightstart'></a>
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#<a id='4275' tid='4276', class="m">include</a> <a id='4277' tid='4278', class="m">&lt;</a><a id='4279' tid='4280', class="m">stdlib</a><a id='4281' tid='4282', class="m">.</a><a id='4283' tid='4284', class="m">h</a><a id='4285' tid='4286', class="m">&gt;</a>
#<a id='4287' tid='4288', class="m">include</a> <a id='4289' tid='4290', class="m">&lt;</a><a id='4291' tid='4292', class="m">errno</a><a id='4293' tid='4294', class="m">.</a><a id='4295' tid='4296', class="m">h</a><a id='4297' tid='4298', class="m">&gt;</a>

<span class="d">#include &quot;d8.h&quot;</span>
<span class="d">#include &quot;d8-debug.h&quot;</span>
<span class="d">#include &quot;debug.h&quot;</span>
<span class="d">#include &quot;api.h&quot;</span>
<span class="d">#include &quot;natives.h&quot;</span>
<span class="d">#include &quot;platform.h&quot;</span>


namespace <span class="d">v8</span> {


<a id='4261' tid='4262', class="m">const</a> <a id='4263' tid='4264', class="m">char</a><a id='4265' tid='4266', class="m">*</a> <a id='4267' tid='4268', class="m">Shell</a><a id='4269' tid='4270', class="m">::</a><a id='4271' tid='4272', class="m">kHistoryFileName</a> = <a id='4273' tid='4274', class="m">&quot;.d8_history&quot;</a>;
<a id='4247' tid='4248', class="m">const</a> <a id='4249' tid='4250', class="m">char</a><a id='4251' tid='4252', class="m">*</a> <a id='4253' tid='4254', class="m">Shell</a><a id='4255' tid='4256', class="m">::</a><a id='4257' tid='4258', class="m">kPrompt</a> = <a id='4259' tid='4260', class="m">&quot;d8&gt; &quot;</a>;


<a id='4205' tid='4206', class="m">LineEditor</a> <a id='4207' tid='4208', class="m">*</a><a id='4209' tid='4210', class="m">LineEditor</a><a id='4211' tid='4212', class="m">::</a><a id='4213' tid='4214', class="m">first_</a> = <a id='4215' tid='4216', class="m">NULL</a>;


<a id='4169' tid='4170', class="m">LineEditor</a><a id='4171' tid='4172', class="m">::</a><a id='4173' tid='4174', class="m">LineEditor</a>(<a id='4175' tid='4176', class="m">Type</a> <a id='4177' tid='4178', class="m">type</a>, <a id='4179' tid='4180', class="m">const</a> <a id='4181' tid='4182', class="m">char</a><a id='4183' tid='4184', class="m">*</a> <a id='4185' tid='4186', class="m">name</a>)
    : <a id='4187' tid='4188', class="m">type_</a>(<a id='4189' tid='4190', class="m">type</a>),
      <a id='4191' tid='4192', class="m">name_</a>(<a id='4193' tid='4194', class="m">name</a>),
      <a id='4195' tid='4196', class="m">next_</a>(<a id='4197' tid='4198', class="m">first_</a>) {
  <a id='4199' tid='4200', class="m">first_</a> <a id='4201' tid='4202', class="m">=</a> <a id='4203' tid='4204', class="m">this</a>;
}


<a id='4105' tid='4106', class="m">LineEditor</a><a id='4107' tid='4108', class="m">*</a> <a id='4109' tid='4110', class="m">LineEditor</a><a id='4111' tid='4112', class="m">::</a><a id='4113' tid='4114', class="m">Get</a>() {
  <a id='4115' tid='4116', class="m">LineEditor</a><a id='4117' tid='4118', class="m">*</a> <a id='4119' tid='4120', class="m">current</a> = <a id='4121' tid='4122', class="m">first_</a>;
  <a id='4123' tid='4124', class="m">LineEditor</a><a id='4125' tid='4126', class="m">*</a> <a id='4127' tid='4128', class="m">best</a> = <a id='4129' tid='4130', class="m">current</a>;
  <a id='4131' tid='4132', class="m">while</a> (<a id='4133' tid='4134', class="m">current</a> <a id='4135' tid='4136', class="m">!=</a> <a id='4137' tid='4138', class="m">NULL</a>) {
    <a id='4139' tid='4140', class="m">if</a> (<a id='4141' tid='4142', class="m">current</a>-&gt;<a id='4143' tid='4144', class="m">type_</a> <a id='4145' tid='4146', class="m">&gt;</a> <a id='4147' tid='4148', class="m">best</a>-&gt;<a id='4149' tid='4150', class="m">type_</a>)
      <a id='4151' tid='4152', class="m">best</a> <a id='4153' tid='4154', class="m">=</a> <a id='4155' tid='4156', class="m">current</a>;
    <a id='4157' tid='4158', class="m">current</a> <a id='4159' tid='4160', class="m">=</a> <a id='4161' tid='4162', class="m">current</a>-&gt;<a id='4163' tid='4164', class="m">next_</a>;
  }
  <a id='4165' tid='4166', class="m">return</a> <a id='4167' tid='4168', class="m">best</a>;
}


<a id='4063' tid='4064', class="m">class</a> <a id='4065' tid='4066', class="m">DumbLineEditor</a>: <a id='4067' tid='4068', class="m">public</a> <a id='4069' tid='4070', class="m">LineEditor</a> {
 <a id='4103' tid='4104', class="m">public</a>:
  <a id='4071' tid='4072', class="m">DumbLineEditor</a>() : <a id='4073' tid='4074', class="m">LineEditor</a>(<a id='4075' tid='4076', class="m">LineEditor</a><a id='4077' tid='4078', class="m">::</a><a id='4079' tid='4080', class="m">DUMB</a>, <a id='4081' tid='4082', class="m">&quot;dumb&quot;</a>) { }
  <a id='4083' tid='4084', class="m">virtual</a> <a id='4085' tid='4086', class="m">i</a><a id='4087' tid='4088', class="m">::</a><a id='4089' tid='4090', class="m">SmartPointer</a>&lt;<a id='4091' tid='4092', class="m">char</a>&gt; <a id='4093' tid='4094', class="m">Prompt</a>(<a id='4095' tid='4096', class="m">const</a> <a id='4097' tid='4098', class="m">char</a><a id='4099' tid='4100', class="m">*</a> <a id='4101' tid='4102', class="m">prompt</a>);
};


<span class="d">static DumbLineEditor dumb_line_editor;</span>


<a id='3983' tid='3984', class="m">i</a><a id='3985' tid='3986', class="m">::</a><a id='3987' tid='3988', class="m">SmartPointer</a>&lt;<a id='3989' tid='3990', class="m">char</a>&gt; <a id='3991' tid='3992', class="m">DumbLineEditor</a><a id='3993' tid='3994', class="m">::</a><a id='3995' tid='3996', class="m">Prompt</a>(<a id='3997' tid='3998', class="m">const</a> <a id='3999' tid='4000', class="m">char</a><a id='4001' tid='4002', class="m">*</a> <a id='4003' tid='4004', class="m">prompt</a>) {
  <a id='4005' tid='4006', class="m">static</a> <a id='4007' tid='4008', class="m">const</a> <a id='4009' tid='4010', class="m">int</a> <a id='4011' tid='4012', class="m">kBufferSize</a> = <a id='4013' tid='4014', class="m">256</a>;
  <a id='4015' tid='4016', class="m">char</a> <a id='4017' tid='4018', class="m">buffer</a>[<a id='4019' tid='4020', class="m">kBufferSize</a>];
  <a id='4021' tid='4022', class="m">printf</a>(<a id='4023' tid='4024', class="m">&quot;%s&quot;</a>, <a id='4025' tid='4026', class="m">prompt</a>);
  <a id='4027' tid='4028', class="m">char</a><a id='4029' tid='4030', class="m">*</a> <a id='4031' tid='4032', class="m">str</a> = <a id='4033' tid='4034', class="m">fgets</a>(<a id='4035' tid='4036', class="m">buffer</a>, <a id='4037' tid='4038', class="m">kBufferSize</a>, <a id='4039' tid='4040', class="m">stdin</a>);
  <a id='4041' tid='4042', class="m">return</a> <a id='4043' tid='4044', class="m">i</a><a id='4045' tid='4046', class="m">::</a><a id='4047' tid='4048', class="m">SmartPointer</a>&lt;<a id='4049' tid='4050', class="m">char</a>&gt;(<a id='4051' tid='4052', class="m">str</a> ? <a id='4053' tid='4054', class="m">i</a><a id='4055' tid='4056', class="m">::</a><a id='4057' tid='4058', class="m">StrDup</a>(<a id='4059' tid='4060', class="m">str</a>) : <a id='4061' tid='4062', class="m">str</a>);
}


<a id='3973' tid='3974', class="m">CounterMap</a><a id='3975' tid='3976', class="m">*</a> <a id='3977' tid='3978', class="m">Shell</a><a id='3979' tid='3980', class="m">::</a><a id='3981' tid='3982', class="m">counter_map_</a>;
<a id='3953' tid='3954', class="m">i</a><a id='3955' tid='3956', class="m">::</a><a id='3957' tid='3958', class="m">OS</a><a id='3959' tid='3960', class="m">::</a><a id='3961' tid='3962', class="m">MemoryMappedFile</a><a id='3963' tid='3964', class="m">*</a> <a id='3965' tid='3966', class="m">Shell</a><a id='3967' tid='3968', class="m">::</a><a id='3969' tid='3970', class="m">counters_file_</a> = <a id='3971' tid='3972', class="m">NULL</a>;
<span class="d">CounterCollection Shell::local_counters_;</span>
<a id='3939' tid='3940', class="m">CounterCollection</a><a id='3941' tid='3942', class="m">*</a> <a id='3943' tid='3944', class="m">Shell</a><a id='3945' tid='3946', class="m">::</a><a id='3947' tid='3948', class="m">counters_</a> = <a id='3949' tid='3950', class="m">&</a><a id='3951' tid='3952', class="m">local_counters_</a>;
<a id='3929' tid='3930', class="m">Persistent</a>&lt;<a id='3931' tid='3932', class="m">Context</a>&gt; <a id='3933' tid='3934', class="m">Shell</a><a id='3935' tid='3936', class="m">::</a><a id='3937' tid='3938', class="m">utility_context_</a>;
<a id='3919' tid='3920', class="m">Persistent</a>&lt;<a id='3921' tid='3922', class="m">Context</a>&gt; <a id='3923' tid='3924', class="m">Shell</a><a id='3925' tid='3926', class="m">::</a><a id='3927' tid='3928', class="m">evaluation_context_</a>;


<a id='3851' tid='3852', class="m">bool</a> <a id='3853' tid='3854', class="m">CounterMap</a><a id='3855' tid='3856', class="m">::</a><a id='3857' tid='3858', class="m">Match</a>(<a id='3859' tid='3860', class="m">void</a><a id='3861' tid='3862', class="m">*</a> <a id='3863' tid='3864', class="m">key1</a>, <a id='3865' tid='3866', class="m">void</a><a id='3867' tid='3868', class="m">*</a> <a id='3869' tid='3870', class="m">key2</a>) {
  <a id='3871' tid='3872', class="m">const</a> <a id='3873' tid='3874', class="m">char</a><a id='3875' tid='3876', class="m">*</a> <a id='3877' tid='3878', class="m">name1</a> = <a id='3879' tid='3880', class="m">reinterpret_cast</a>&lt;<a id='3881' tid='3882', class="m">const</a> <a id='3883' tid='3884', class="m">char</a><a id='3885' tid='3886', class="m">*</a>&gt;(<a id='3887' tid='3888', class="m">key1</a>);
  <a id='3889' tid='3890', class="m">const</a> <a id='3891' tid='3892', class="m">char</a><a id='3893' tid='3894', class="m">*</a> <a id='3895' tid='3896', class="m">name2</a> = <a id='3897' tid='3898', class="m">reinterpret_cast</a>&lt;<a id='3899' tid='3900', class="m">const</a> <a id='3901' tid='3902', class="m">char</a><a id='3903' tid='3904', class="m">*</a>&gt;(<a id='3905' tid='3906', class="m">key2</a>);
  <a id='3907' tid='3908', class="m">return</a> <a id='3909' tid='3910', class="m">strcmp</a>(<a id='3911' tid='3912', class="m">name1</a>, <a id='3913' tid='3914', class="m">name2</a>) <a id='3915' tid='3916', class="m">==</a> <a id='3917' tid='3918', class="m">0</a>;
}


// Converts a V8 value to a C string.
<span class="d">const</span> <span class="d">char*</span> <span class="d">ToCString</span>(<a id='3835' tid='3836', class="m">const</a> <a id='3837' tid='3838', class="m">v8</a><a id='3839' tid='3840', class="m">::</a><a id='3841' tid='3842', class="m">String</a><a id='3843' tid='3844', class="m">::</a><a id='3845' tid='3846', class="m">Utf8Value</a><a id='3847' tid='3848', class="m">&</a> <a id='3849' tid='3850', class="m">value</a>) {
  <a id='3643' tid='3644', class="m">return</a> <a id='3645' tid='3646', class="m">*</a><a id='3647' tid='3648', class="m">value</a> ? <a id='3649' tid='3650', class="m">*</a><a id='3651' tid='3652', class="m">value</a> : <a id='3653' tid='3654', class="m">&quot;&lt;string conversion failed&gt;&quot;</a>;
}


// Executes a string within the current v8 context.
<a id='3655' tid='3656', class="m">bool</a> <a id='3657' tid='3658', class="m">Shell</a><a id='3659' tid='3660', class="m">::</a><a id='3661' tid='3662', class="m">ExecuteString</a>(<a id='3663' tid='3664', class="m">Handle</a>&lt;<a id='3665' tid='3666', class="m">String</a>&gt; <a id='3667' tid='3668', class="m">source</a>,
                          <a id='3669' tid='3670', class="m">Handle</a>&lt;<a id='3671' tid='3672', class="m">Value</a>&gt; <a id='3673' tid='3674', class="m">name</a>,
                          <a id='3675' tid='3676', class="m">bool</a> <a id='3677' tid='3678', class="m">print_result</a>,
                          <a id='3679' tid='3680', class="m">bool</a> <a id='3681' tid='3682', class="m">report_exceptions</a>) {
  <a id='3683' tid='3684', class="m">HandleScope</a> <a id='3685' tid='3686', class="m">handle_scope</a>;
  <a id='3687' tid='3688', class="m">TryCatch</a> <a id='3689' tid='3690', class="m">try_catch</a>;
  <a id='3691' tid='3692', class="m">if</a> (<a id='3693' tid='3694', class="m">i</a><a id='3695' tid='3696', class="m">::</a><a id='3697' tid='3698', class="m">FLAG_debugger</a>) {
    // When debugging make exceptions appear to be uncaught.
    <a id='3699' tid='3700', class="m">try_catch</a>.<a id='3701' tid='3702', class="m">SetVerbose</a>(<a id='3703' tid='3704', class="m">true</a>);
  }
  <a id='3705' tid='3706', class="m">Handle</a>&lt;<a id='3707' tid='3708', class="m">Script</a>&gt; <a id='3709' tid='3710', class="m">script</a> = <a id='3711' tid='3712', class="m">Script</a><a id='3713' tid='3714', class="m">::</a><a id='3715' tid='3716', class="m">Compile</a>(<a id='3717' tid='3718', class="m">source</a>, <a id='3719' tid='3720', class="m">name</a>);
  <a id='3721' tid='3722', class="m">if</a> (<a id='3723' tid='3724', class="m">script</a>.<a id='3725' tid='3726', class="m">IsEmpty</a>()) {
    // Print errors that happened during compilation.
    <a id='3727' tid='3728', class="m">if</a> (<a id='3729' tid='3730', class="m">report_exceptions</a> <a id='3731' tid='3732', class="m">&&</a> <a id='3733' tid='3734', class="m">!</a><a id='3735' tid='3736', class="m">i</a><a id='3737' tid='3738', class="m">::</a><a id='3739' tid='3740', class="m">FLAG_debugger</a>)
      <a id='3741' tid='3742', class="m">ReportException</a>(<a id='3743' tid='3744', class="m">&</a><a id='3745' tid='3746', class="m">try_catch</a>);
    <a id='3747' tid='3748', class="m">return</a> <a id='3749' tid='3750', class="m">false</a>;
  } <a id='3751' tid='3752', class="m">else</a> {
    <a id='3753' tid='3754', class="m">Handle</a>&lt;<a id='3755' tid='3756', class="m">Value</a>&gt; <a id='3757' tid='3758', class="m">result</a> = <a id='3759' tid='3760', class="m">script</a>-&gt;<a id='3761' tid='3762', class="m">Run</a>();
    <a id='3763' tid='3764', class="m">if</a> (<a id='3765' tid='3766', class="m">result</a>.<a id='3767' tid='3768', class="m">IsEmpty</a>()) {
      // Print errors that happened during execution.
      <a id='3769' tid='3770', class="m">if</a> (<a id='3771' tid='3772', class="m">report_exceptions</a> <a id='3773' tid='3774', class="m">&&</a> <a id='3775' tid='3776', class="m">!</a><a id='3777' tid='3778', class="m">i</a><a id='3779' tid='3780', class="m">::</a><a id='3781' tid='3782', class="m">FLAG_debugger</a>)
        <a id='3783' tid='3784', class="m">ReportException</a>(<a id='3785' tid='3786', class="m">&</a><a id='3787' tid='3788', class="m">try_catch</a>);
      <span class="d">return false;</span>
    } <a id='3789' tid='3790', class="m">else</a> {
      <a id='3791' tid='3792', class="m">if</a> (<a id='3793' tid='3794', class="m">print_result</a> <a id='3795' tid='3796', class="m">&&</a> <a id='3797' tid='3798', class="m">!</a><a id='3799' tid='3800', class="m">result</a>-&gt;<a id='3801' tid='3802', class="m">IsUndefined</a>()) {
        // If all went well and the result wasn&#39;t undefined then print
        // the returned value.
        <a id='3803' tid='3804', class="m">v8</a><a id='3805' tid='3806', class="m">::</a><a id='3807' tid='3808', class="m">String</a><a id='3809' tid='3810', class="m">::</a><a id='3811' tid='3812', class="m">Utf8Value</a> <a id='3813' tid='3814', class="m">str</a>(<a id='3815' tid='3816', class="m">result</a>);
        <a id='3817' tid='3818', class="m">const</a> <a id='3819' tid='3820', class="m">char</a><a id='3821' tid='3822', class="m">*</a> <a id='3823' tid='3824', class="m">cstr</a> = <a id='3825' tid='3826', class="m">ToCString</a>(<a id='3827' tid='3828', class="m">str</a>);
        <a id='3829' tid='3830', class="m">printf</a>(<a id='3831' tid='3832', class="m">&quot;%s\n&quot;</a>, <a id='3833' tid='3834', class="m">cstr</a>);
      }
      <span class="d">return true;</span>
    }
  }
}


<a id='3607' tid='3608', class="m">Handle</a>&lt;<a id='3609' tid='3610', class="m">Value</a>&gt; <a id='3611' tid='3612', class="m">Shell</a><a id='3613' tid='3614', class="m">::</a><a id='3615' tid='3616', class="m">Print</a>(<a id='3617' tid='3618', class="m">const</a> <a id='3619' tid='3620', class="m">Arguments</a><a id='3621' tid='3622', class="m">&</a> <a id='3623' tid='3624', class="m">args</a>) {
  <a id='3625' tid='3626', class="m">Handle</a>&lt;<a id='3627' tid='3628', class="m">Value</a>&gt; <a id='3629' tid='3630', class="m">val</a> = <a id='3631' tid='3632', class="m">Write</a>(<a id='3633' tid='3634', class="m">args</a>);
  <a id='3635' tid='3636', class="m">printf</a>(<a id='3637' tid='3638', class="m">&quot;\n&quot;</a>);
  <a id='3639' tid='3640', class="m">return</a> <a id='3641' tid='3642', class="m">val</a>;
}


<a id='3491' tid='3492', class="m">Handle</a>&lt;<a id='3493' tid='3494', class="m">Value</a>&gt; <a id='3495' tid='3496', class="m">Shell</a><a id='3497' tid='3498', class="m">::</a><a id='3499' tid='3500', class="m">Write</a>(<a id='3501' tid='3502', class="m">const</a> <a id='3503' tid='3504', class="m">Arguments</a><a id='3505' tid='3506', class="m">&</a> <a id='3507' tid='3508', class="m">args</a>) {
  <a id='3509' tid='3510', class="m">for</a> (<a id='3511' tid='3512', class="m">int</a> <a id='3513' tid='3514', class="m">i</a> = <a id='3515' tid='3516', class="m">0</a>; <a id='3517' tid='3518', class="m">i</a> <a id='3519' tid='3520', class="m">&lt;</a> <a id='3521' tid='3522', class="m">args</a>.<a id='3523' tid='3524', class="m">Length</a>(); <a id='3525' tid='3526', class="m">i</a><a id='3527' tid='3528', class="m">++</a>) {
    <a id='3529' tid='3530', class="m">HandleScope</a> <a id='3531' tid='3532', class="m">handle_scope</a>;
    <a id='3533' tid='3534', class="m">if</a> (<a id='3535' tid='3536', class="m">i</a> <a id='3537' tid='3538', class="m">!=</a> <a id='3539' tid='3540', class="m">0</a>) {
      <a id='3541' tid='3542', class="m">printf</a>(<a id='3543' tid='3544', class="m">&quot; &quot;</a>);
    }
    <a id='3545' tid='3546', class="m">v8</a><a id='3547' tid='3548', class="m">::</a><a id='3549' tid='3550', class="m">String</a><a id='3551' tid='3552', class="m">::</a><a id='3553' tid='3554', class="m">Utf8Value</a> <a id='3555' tid='3556', class="m">str</a>(<a id='3557' tid='3558', class="m">args</a>[<a id='3559' tid='3560', class="m">i</a>]);
    <a id='3561' tid='3562', class="m">int</a> <a id='3563' tid='3564', class="m">n</a> = <a id='3565' tid='3566', class="m">fwrite</a>(<a id='3567' tid='3568', class="m">*</a><a id='3569' tid='3570', class="m">str</a>, <a id='3571' tid='3572', class="m">sizeof</a>(<a id='3573' tid='3574', class="m">*</a><a id='3575' tid='3576', class="m">*</a><a id='3577' tid='3578', class="m">str</a>), <a id='3579' tid='3580', class="m">str</a>.<a id='3581' tid='3582', class="m">length</a>(), <a id='3583' tid='3584', class="m">stdout</a>);
    <a id='3585' tid='3586', class="m">if</a> (<a id='3587' tid='3588', class="m">n</a> <a id='3589' tid='3590', class="m">!=</a> <a id='3591' tid='3592', class="m">str</a>.<a id='3593' tid='3594', class="m">length</a>()) {
      <a id='3595' tid='3596', class="m">printf</a>(<a id='3597' tid='3598', class="m">&quot;Error in fwrite\n&quot;</a>);
      <a id='3599' tid='3600', class="m">exit</a>(<a id='3601' tid='3602', class="m">1</a>);
    }
  }
  <a id='3603' tid='3604', class="m">return</a> <a id='3605' tid='3606', class="m">Undefined</a>();
}


<a id='3405' tid='3406', class="m">Handle</a>&lt;<a id='3407' tid='3408', class="m">Value</a>&gt; <a id='3409' tid='3410', class="m">Shell</a><a id='3411' tid='3412', class="m">::</a><a id='3413' tid='3414', class="m">Read</a>(<a id='3415' tid='3416', class="m">const</a> <a id='3417' tid='3418', class="m">Arguments</a><a id='3419' tid='3420', class="m">&</a> <a id='3421' tid='3422', class="m">args</a>) {
  <a id='3423' tid='3424', class="m">String</a><a id='3425' tid='3426', class="m">::</a><a id='3427' tid='3428', class="m">Utf8Value</a> <a id='3429' tid='3430', class="m">file</a>(<a id='3431' tid='3432', class="m">args</a>[<a id='3433' tid='3434', class="m">0</a>]);
  <a id='3435' tid='3436', class="m">if</a> (<a id='3437' tid='3438', class="m">*</a><a id='3439' tid='3440', class="m">file</a> <a id='3441' tid='3442', class="m">==</a> <a id='3443' tid='3444', class="m">NULL</a>) {
    <a id='3445' tid='3446', class="m">return</a> <a id='3447' tid='3448', class="m">ThrowException</a>(<a id='3449' tid='3450', class="m">String</a><a id='3451' tid='3452', class="m">::</a><a id='3453' tid='3454', class="m">New</a>(<a id='3455' tid='3456', class="m">&quot;Error loading file&quot;</a>));
  }
  <a id='3457' tid='3458', class="m">Handle</a>&lt;<a id='3459' tid='3460', class="m">String</a>&gt; <a id='3461' tid='3462', class="m">source</a> = <a id='3463' tid='3464', class="m">ReadFile</a>(<a id='3465' tid='3466', class="m">*</a><a id='3467' tid='3468', class="m">file</a>);
  <a id='3469' tid='3470', class="m">if</a> (<a id='3471' tid='3472', class="m">source</a>.<a id='3473' tid='3474', class="m">IsEmpty</a>()) {
    <a id='3475' tid='3476', class="m">return</a> <a id='3477' tid='3478', class="m">ThrowException</a>(<a id='3479' tid='3480', class="m">String</a><a id='3481' tid='3482', class="m">::</a><a id='3483' tid='3484', class="m">New</a>(<a id='3485' tid='3486', class="m">&quot;Error loading file&quot;</a>));
  }
  <a id='3487' tid='3488', class="m">return</a> <a id='3489' tid='3490', class="m">source</a>;
}


<a id='3305' tid='3306', class="m">Handle</a>&lt;<a id='3307' tid='3308', class="m">Value</a>&gt; <a id='3309' tid='3310', class="m">Shell</a><a id='3311' tid='3312', class="m">::</a><a id='3313' tid='3314', class="m">ReadLine</a>(<a id='3315' tid='3316', class="m">const</a> <a id='3317' tid='3318', class="m">Arguments</a><a id='3319' tid='3320', class="m">&</a> <a id='3321' tid='3322', class="m">args</a>) {
  <a id='3323' tid='3324', class="m">i</a><a id='3325' tid='3326', class="m">::</a><a id='3327' tid='3328', class="m">SmartPointer</a>&lt;<a id='3329' tid='3330', class="m">char</a>&gt; <a id='3331' tid='3332', class="m">line</a>(<a id='3333' tid='3334', class="m">i</a><a id='3335' tid='3336', class="m">::</a><a id='3337' tid='3338', class="m">ReadLine</a>(<a id='3339' tid='3340', class="m">&quot;&quot;</a>));
  <a id='3341' tid='3342', class="m">if</a> (<a id='3343' tid='3344', class="m">*</a><a id='3345' tid='3346', class="m">line</a> <a id='3347' tid='3348', class="m">==</a> <a id='3349' tid='3350', class="m">NULL</a>) {
    <a id='3351' tid='3352', class="m">return</a> <a id='3353' tid='3354', class="m">Null</a>();
  }
  <a id='3355' tid='3356', class="m">size_t</a> <a id='3357' tid='3358', class="m">len</a> = <a id='3359' tid='3360', class="m">strlen</a>(<a id='3361' tid='3362', class="m">*</a><a id='3363' tid='3364', class="m">line</a>);
  <a id='3365' tid='3366', class="m">if</a> (<a id='3367' tid='3368', class="m">len</a> <a id='3369' tid='3370', class="m">&gt;</a> <a id='3371' tid='3372', class="m">0</a> <a id='3373' tid='3374', class="m">&&</a> <a id='3375' tid='3376', class="m">line</a>[<a id='3377' tid='3378', class="m">len</a> <a id='3379' tid='3380', class="m">-</a> <a id='3381' tid='3382', class="m">1</a>] <a id='3383' tid='3384', class="m">==</a> <a id='3385' tid='3386', class="m">&#39;\n&#39;</a>) {
    <a id='3387' tid='3388', class="m">--</a><a id='3389' tid='3390', class="m">len</a>;
  }
  <a id='3391' tid='3392', class="m">return</a> <a id='3393' tid='3394', class="m">String</a><a id='3395' tid='3396', class="m">::</a><a id='3397' tid='3398', class="m">New</a>(<a id='3399' tid='3400', class="m">*</a><a id='3401' tid='3402', class="m">line</a>, <a id='3403' tid='3404', class="m">len</a>);
}


<a id='3161' tid='3162', class="m">Handle</a>&lt;<a id='3163' tid='3164', class="m">Value</a>&gt; <a id='3165' tid='3166', class="m">Shell</a><a id='3167' tid='3168', class="m">::</a><a id='3169' tid='3170', class="m">Load</a>(<a id='3171' tid='3172', class="m">const</a> <a id='3173' tid='3174', class="m">Arguments</a><a id='3175' tid='3176', class="m">&</a> <a id='3177' tid='3178', class="m">args</a>) {
  <a id='3179' tid='3180', class="m">for</a> (<a id='3181' tid='3182', class="m">int</a> <a id='3183' tid='3184', class="m">i</a> = <a id='3185' tid='3186', class="m">0</a>; <a id='3187' tid='3188', class="m">i</a> <a id='3189' tid='3190', class="m">&lt;</a> <a id='3191' tid='3192', class="m">args</a>.<a id='3193' tid='3194', class="m">Length</a>(); <a id='3195' tid='3196', class="m">i</a><a id='3197' tid='3198', class="m">++</a>) {
    <a id='3199' tid='3200', class="m">HandleScope</a> <a id='3201' tid='3202', class="m">handle_scope</a>;
    <a id='3203' tid='3204', class="m">String</a><a id='3205' tid='3206', class="m">::</a><a id='3207' tid='3208', class="m">Utf8Value</a> <a id='3209' tid='3210', class="m">file</a>(<a id='3211' tid='3212', class="m">args</a>[<a id='3213' tid='3214', class="m">i</a>]);
    <a id='3215' tid='3216', class="m">if</a> (<a id='3217' tid='3218', class="m">*</a><a id='3219' tid='3220', class="m">file</a> <a id='3221' tid='3222', class="m">==</a> <a id='3223' tid='3224', class="m">NULL</a>) {
      <a id='3225' tid='3226', class="m">return</a> <a id='3227' tid='3228', class="m">ThrowException</a>(<a id='3229' tid='3230', class="m">String</a><a id='3231' tid='3232', class="m">::</a><a id='3233' tid='3234', class="m">New</a>(<a id='3235' tid='3236', class="m">&quot;Error loading file&quot;</a>));
    }
    <a id='3237' tid='3238', class="m">Handle</a>&lt;<a id='3239' tid='3240', class="m">String</a>&gt; <a id='3241' tid='3242', class="m">source</a> = <a id='3243' tid='3244', class="m">ReadFile</a>(<a id='3245' tid='3246', class="m">*</a><a id='3247' tid='3248', class="m">file</a>);
    <a id='3249' tid='3250', class="m">if</a> (<a id='3251' tid='3252', class="m">source</a>.<a id='3253' tid='3254', class="m">IsEmpty</a>()) {
      <a id='3255' tid='3256', class="m">return</a> <a id='3257' tid='3258', class="m">ThrowException</a>(<a id='3259' tid='3260', class="m">String</a><a id='3261' tid='3262', class="m">::</a><a id='3263' tid='3264', class="m">New</a>(<a id='3265' tid='3266', class="m">&quot;Error loading file&quot;</a>));
    }
    <a id='3267' tid='3268', class="m">if</a> (<a id='3269' tid='3270', class="m">!</a><a id='3271' tid='3272', class="m">ExecuteString</a>(<a id='3273' tid='3274', class="m">source</a>, <a id='3275' tid='3276', class="m">String</a><a id='3277' tid='3278', class="m">::</a><a id='3279' tid='3280', class="m">New</a>(<a id='3281' tid='3282', class="m">*</a><a id='3283' tid='3284', class="m">file</a>), <a id='3285' tid='3286', class="m">false</a>, <a id='3287' tid='3288', class="m">false</a>)) {
      <a id='3289' tid='3290', class="m">return</a> <a id='3291' tid='3292', class="m">ThrowException</a>(<a id='3293' tid='3294', class="m">String</a><a id='3295' tid='3296', class="m">::</a><a id='3297' tid='3298', class="m">New</a>(<a id='3299' tid='3300', class="m">&quot;Error executing file&quot;</a>));
    }
  }
  <a id='3301' tid='3302', class="m">return</a> <a id='3303' tid='3304', class="m">Undefined</a>();
}


<a id='3131' tid='3132', class="m">Handle</a>&lt;<a id='3133' tid='3134', class="m">Value</a>&gt; <a id='3135' tid='3136', class="m">Shell</a><a id='3137' tid='3138', class="m">::</a><a id='3139' tid='3140', class="m">Yield</a>(<a id='3141' tid='3142', class="m">const</a> <a id='3143' tid='3144', class="m">Arguments</a><a id='3145' tid='3146', class="m">&</a> <a id='3147' tid='3148', class="m">args</a>) {
  <a id='3149' tid='3150', class="m">v8</a><a id='3151' tid='3152', class="m">::</a><a id='3153' tid='3154', class="m">Unlocker</a> <a id='3155' tid='3156', class="m">unlocker</a>;
  <a id='3157' tid='3158', class="m">return</a> <a id='3159' tid='3160', class="m">Undefined</a>();
}


<a id='3093' tid='3094', class="m">Handle</a>&lt;<a id='3095' tid='3096', class="m">Value</a>&gt; <a id='3097' tid='3098', class="m">Shell</a><a id='3099' tid='3100', class="m">::</a><a id='3101' tid='3102', class="m">Quit</a>(<a id='3103' tid='3104', class="m">const</a> <a id='3105' tid='3106', class="m">Arguments</a><a id='3107' tid='3108', class="m">&</a> <a id='3109' tid='3110', class="m">args</a>) {
  <a id='3111' tid='3112', class="m">int</a> <a id='3113' tid='3114', class="m">exit_code</a> = <a id='3115' tid='3116', class="m">args</a>[<a id='3117' tid='3118', class="m">0</a>]-&gt;<a id='3119' tid='3120', class="m">Int32Value</a>();
  <a id='3121' tid='3122', class="m">OnExit</a>();
  <a id='3123' tid='3124', class="m">exit</a>(<a id='3125' tid='3126', class="m">exit_code</a>);
  <a id='3127' tid='3128', class="m">return</a> <a id='3129' tid='3130', class="m">Undefined</a>();
}


<a id='3061' tid='3062', class="m">Handle</a>&lt;<a id='3063' tid='3064', class="m">Value</a>&gt; <a id='3065' tid='3066', class="m">Shell</a><a id='3067' tid='3068', class="m">::</a><a id='3069' tid='3070', class="m">Version</a>(<a id='3071' tid='3072', class="m">const</a> <a id='3073' tid='3074', class="m">Arguments</a><a id='3075' tid='3076', class="m">&</a> <a id='3077' tid='3078', class="m">args</a>) {
  <a id='3079' tid='3080', class="m">return</a> <a id='3081' tid='3082', class="m">String</a><a id='3083' tid='3084', class="m">::</a><a id='3085' tid='3086', class="m">New</a>(<a id='3087' tid='3088', class="m">V8</a><a id='3089' tid='3090', class="m">::</a><a id='3091' tid='3092', class="m">GetVersion</a>());
}


<a id='2971' tid='2972', class="m">void</a> <a id='2973' tid='2974', class="m">Shell</a><a id='2975' tid='2976', class="m">::</a><a id='2977' tid='2978', class="m">ReportException</a>(<a id='2979' tid='2980', class="m">v8</a><a id='2981' tid='2982', class="m">::</a><a id='2983' tid='2984', class="m">TryCatch</a><a id='2985' tid='2986', class="m">*</a> <a id='2987' tid='2988', class="m">try_catch</a>) {
  <a id='2989' tid='2990', class="m">HandleScope</a> <a id='2991' tid='2992', class="m">handle_scope</a>;
  <a id='2993' tid='2994', class="m">v8</a><a id='2995' tid='2996', class="m">::</a><a id='2997' tid='2998', class="m">String</a><a id='2999' tid='3000', class="m">::</a><a id='3001' tid='3002', class="m">Utf8Value</a> <a id='3003' tid='3004', class="m">exception</a>(<a id='3005' tid='3006', class="m">try_catch</a>-&gt;<a id='3007' tid='3008', class="m">Exception</a>());
  <a id='3009' tid='3010', class="m">const</a> <a id='3011' tid='3012', class="m">char</a><a id='3013' tid='3014', class="m">*</a> <a id='3015' tid='3016', class="m">exception_string</a> = <a id='3017' tid='3018', class="m">ToCString</a>(<a id='3019' tid='3020', class="m">exception</a>);
  <a id='3021' tid='3022', class="m">Handle</a>&lt;<a id='3023' tid='3024', class="m">Message</a>&gt; <a id='3025' tid='3026', class="m">message</a> = <a id='3027' tid='3028', class="m">try_catch</a>-&gt;<a id='3029' tid='3030', class="m">Message</a>();
  <a id='3031' tid='3032', class="m">if</a> (<a id='3033' tid='3034', class="m">message</a>.<a id='3035' tid='3036', class="m">IsEmpty</a>()) {
    // V8 didn&#39;t provide any extra information about this error; just
    // print the exception.
    <a id='3037' tid='3038', class="m">printf</a>(<a id='3039' tid='3040', class="m">&quot;%s\n&quot;</a>, <a id='3041' tid='3042', class="m">exception_string</a>);
  } <a id='3043' tid='3044', class="m">else</a> {
    // Print (filename):(line number): (message).
    <a id='3045' tid='3046', class="m">v8</a><a id='3047' tid='3048', class="m">::</a><a id='3049' tid='3050', class="m">String</a><a id='3051' tid='3052', class="m">::</a><a id='3053' tid='3054', class="m">Utf8Value</a> <a id='3055' tid='3056', class="m">filename</a>(<a id='3057' tid='3058', class="m">message</a>-&gt;<a id='3059' tid='3060', class="m">GetScriptResourceName</a>());
    <a id='2959' tid='2960', class="m">const</a> <a id='2961' tid='2962', class="m">char</a><a id='2963' tid='2964', class="m">*</a> <a id='2965' tid='2966', class="m">filename_string</a> = <a id='2967' tid='2968', class="m">ToCString</a>(<a id='2969' tid='2970', class="m">filename</a>);
    <span class="d">int linenum = message-&gt;GetLineNumber();</span>
    <a id='2819' tid='2820', class="m">printf</a>(<a id='2821' tid='2822', class="m">&quot;%s:%i: %s\n&quot;</a>, <a id='2823' tid='2824', class="m">filename_string</a>, <a id='2825' tid='2826', class="m">linenum</a>, <a id='2827' tid='2828', class="m">exception_string</a>);
    // Print line of source code.
    <a id='2693' tid='2694', class="m">v8</a><a id='2695' tid='2696', class="m">::</a><a id='2697' tid='2698', class="m">String</a><a id='2699' tid='2700', class="m">::</a><a id='2701' tid='2702', class="m">Utf8Value</a> <a id='2703' tid='2704', class="m">sourceline</a>(<a id='2705' tid='2706', class="m">message</a>-&gt;<a id='2707' tid='2708', class="m">GetSourceLine</a>());
    <a id='2579' tid='2580', class="m">const</a> <a id='2581' tid='2582', class="m">char</a><a id='2583' tid='2584', class="m">*</a> <a id='2585' tid='2586', class="m">sourceline_string</a> = <a id='2587' tid='2588', class="m">ToCString</a>(<a id='2589' tid='2590', class="m">sourceline</a>);
    <span class="d">printf(&quot;%s\n&quot;, sourceline_string);</span>
    // Print wavy underline (GetUnderline is deprecated).
    <span class="d">int start = message-&gt;GetStartColumn();</span>
    <a id='2471' tid='2472', class="m">for</a> (<a id='2473' tid='2474', class="m">int</a> <a id='2475' tid='2476', class="m">i</a> = <a id='2477' tid='2478', class="m">0</a>; <a id='2479' tid='2480', class="m">i</a> <a id='2481' tid='2482', class="m">&lt;</a> <a id='2483' tid='2484', class="m">start</a>; <a id='2485' tid='2486', class="m">i</a><a id='2487' tid='2488', class="m">++</a>) {
      <a id='2489' tid='2490', class="m">printf</a>(<a id='2491' tid='2492', class="m">&quot; &quot;</a>);
    }
    <span class="d">int end = message-&gt;GetEndColumn();</span>
    <a id='2427' tid='2428', class="m">for</a> (<a id='2429' tid='2430', class="m">int</a> <a id='2431' tid='2432', class="m">i</a> = <a id='2433' tid='2434', class="m">start</a>; <a id='2435' tid='2436', class="m">i</a> <a id='2437' tid='2438', class="m">&lt;</a> <a id='2439' tid='2440', class="m">end</a>; <a id='2441' tid='2442', class="m">i</a><a id='2443' tid='2444', class="m">++</a>) {
      <a id='2445' tid='2446', class="m">printf</a>(<a id='2447' tid='2448', class="m">&quot;^&quot;</a>);
    }
    <span class="d">printf(&quot;\n&quot;);</span>
  }
}


<a id='2829' tid='2830', class="m">Handle</a>&lt;<a id='2831' tid='2832', class="m">Array</a>&gt; <a id='2833' tid='2834', class="m">Shell</a><a id='2835' tid='2836', class="m">::</a><a id='2837' tid='2838', class="m">GetCompletions</a>(<a id='2839' tid='2840', class="m">Handle</a>&lt;<a id='2841' tid='2842', class="m">String</a>&gt; <a id='2843' tid='2844', class="m">text</a>, <a id='2845' tid='2846', class="m">Handle</a>&lt;<a id='2847' tid='2848', class="m">String</a>&gt; <a id='2849' tid='2850', class="m">full</a>) {
  <a id='2861' tid='2862', class="m">HandleScope</a> <a id='2863' tid='2864', class="m">handle_scope</a>;
  <a id='2851' tid='2852', class="m">Context</a><a id='2853' tid='2854', class="m">::</a><a id='2855' tid='2856', class="m">Scope</a> <a id='2857' tid='2858', class="m">context_scope</a>(<a id='2859' tid='2860', class="m">utility_context_</a>);
  <a id='2865' tid='2866', class="m">Handle</a>&lt;<a id='2867' tid='2868', class="m">Object</a>&gt; <a id='2869' tid='2870', class="m">global</a> = <a id='2871' tid='2872', class="m">utility_context_</a>-&gt;<a id='2873' tid='2874', class="m">Global</a>();
  <a id='2875' tid='2876', class="m">Handle</a>&lt;<a id='2877' tid='2878', class="m">Value</a>&gt; <a id='2879' tid='2880', class="m">fun</a> = <a id='2881' tid='2882', class="m">global</a>-&gt;<a id='2883' tid='2884', class="m">Get</a>(<a id='2885' tid='2886', class="m">String</a><a id='2887' tid='2888', class="m">::</a><a id='2889' tid='2890', class="m">New</a>(<a id='2891' tid='2892', class="m">&quot;GetCompletions&quot;</a>));
  <a id='2893' tid='2894', class="m">static</a> <a id='2895' tid='2896', class="m">const</a> <a id='2897' tid='2898', class="m">int</a> <a id='2899' tid='2900', class="m">kArgc</a> = <a id='2901' tid='2902', class="m">3</a>;
  <a id='2903' tid='2904', class="m">Handle</a>&lt;<a id='2905' tid='2906', class="m">Value</a>&gt; <a id='2907' tid='2908', class="m">argv</a>[<a id='2909' tid='2910', class="m">kArgc</a>] = { <a id='2911' tid='2912', class="m">evaluation_context_</a>-&gt;<a id='2913' tid='2914', class="m">Global</a>(), <a id='2915' tid='2916', class="m">text</a>, <a id='2917' tid='2918', class="m">full</a> };
  <a id='2919' tid='2920', class="m">Handle</a>&lt;<a id='2921' tid='2922', class="m">Value</a>&gt; <a id='2923' tid='2924', class="m">val</a> = <a id='2925' tid='2926', class="m">Handle</a>&lt;<a id='2927' tid='2928', class="m">Function</a>&gt;<a id='2929' tid='2930', class="m">::</a><a id='2931' tid='2932', class="m">Cast</a>(<a id='2933' tid='2934', class="m">fun</a>)-&gt;<a id='2935' tid='2936', class="m">Call</a>(<a id='2937' tid='2938', class="m">global</a>, <a id='2939' tid='2940', class="m">kArgc</a>, <a id='2941' tid='2942', class="m">argv</a>);
  <a id='2943' tid='2944', class="m">return</a> <a id='2945' tid='2946', class="m">handle_scope</a>.<a id='2947' tid='2948', class="m">Close</a>(<a id='2949' tid='2950', class="m">Handle</a>&lt;<a id='2951' tid='2952', class="m">Array</a>&gt;<a id='2953' tid='2954', class="m">::</a><a id='2955' tid='2956', class="m">Cast</a>(<a id='2957' tid='2958', class="m">val</a>));
}


<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
<a id='2709' tid='2710', class="m">Handle</a>&lt;<a id='2711' tid='2712', class="m">Object</a>&gt; <a id='2713' tid='2714', class="m">Shell</a><a id='2715' tid='2716', class="m">::</a><a id='2717' tid='2718', class="m">DebugMessageDetails</a>(<a id='2719' tid='2720', class="m">Handle</a>&lt;<a id='2721' tid='2722', class="m">String</a>&gt; <a id='2723' tid='2724', class="m">message</a>) {
  <a id='2725' tid='2726', class="m">Context</a><a id='2727' tid='2728', class="m">::</a><a id='2729' tid='2730', class="m">Scope</a> <a id='2731' tid='2732', class="m">context_scope</a>(<a id='2733' tid='2734', class="m">utility_context_</a>);
  <a id='2735' tid='2736', class="m">Handle</a>&lt;<a id='2737' tid='2738', class="m">Object</a>&gt; <a id='2739' tid='2740', class="m">global</a> = <a id='2741' tid='2742', class="m">utility_context_</a>-&gt;<a id='2743' tid='2744', class="m">Global</a>();
  <a id='2745' tid='2746', class="m">Handle</a>&lt;<a id='2747' tid='2748', class="m">Value</a>&gt; <a id='2749' tid='2750', class="m">fun</a> = <a id='2751' tid='2752', class="m">global</a>-&gt;<a id='2753' tid='2754', class="m">Get</a>(<a id='2755' tid='2756', class="m">String</a><a id='2757' tid='2758', class="m">::</a><a id='2759' tid='2760', class="m">New</a>(<a id='2761' tid='2762', class="m">&quot;DebugMessageDetails&quot;</a>));
  <a id='2763' tid='2764', class="m">static</a> <a id='2765' tid='2766', class="m">const</a> <a id='2767' tid='2768', class="m">int</a> <a id='2769' tid='2770', class="m">kArgc</a> = <a id='2771' tid='2772', class="m">1</a>;
  <a id='2773' tid='2774', class="m">Handle</a>&lt;<a id='2775' tid='2776', class="m">Value</a>&gt; <a id='2777' tid='2778', class="m">argv</a>[<a id='2779' tid='2780', class="m">kArgc</a>] = { <a id='2781' tid='2782', class="m">message</a> };
  <a id='2783' tid='2784', class="m">Handle</a>&lt;<a id='2785' tid='2786', class="m">Value</a>&gt; <a id='2787' tid='2788', class="m">val</a> = <a id='2789' tid='2790', class="m">Handle</a>&lt;<a id='2791' tid='2792', class="m">Function</a>&gt;<a id='2793' tid='2794', class="m">::</a><a id='2795' tid='2796', class="m">Cast</a>(<a id='2797' tid='2798', class="m">fun</a>)-&gt;<a id='2799' tid='2800', class="m">Call</a>(<a id='2801' tid='2802', class="m">global</a>, <a id='2803' tid='2804', class="m">kArgc</a>, <a id='2805' tid='2806', class="m">argv</a>);
  <a id='2807' tid='2808', class="m">return</a> <a id='2809' tid='2810', class="m">Handle</a>&lt;<a id='2811' tid='2812', class="m">Object</a>&gt;<a id='2813' tid='2814', class="m">::</a><a id='2815' tid='2816', class="m">Cast</a>(<a id='2817' tid='2818', class="m">val</a>);
}


<a id='2591' tid='2592', class="m">Handle</a>&lt;<a id='2593' tid='2594', class="m">Value</a>&gt; <a id='2595' tid='2596', class="m">Shell</a><a id='2597' tid='2598', class="m">::</a><a id='2599' tid='2600', class="m">DebugCommandToJSONRequest</a>(<a id='2601' tid='2602', class="m">Handle</a>&lt;<a id='2603' tid='2604', class="m">String</a>&gt; <a id='2605' tid='2606', class="m">command</a>) {
  <a id='2607' tid='2608', class="m">Context</a><a id='2609' tid='2610', class="m">::</a><a id='2611' tid='2612', class="m">Scope</a> <a id='2613' tid='2614', class="m">context_scope</a>(<a id='2615' tid='2616', class="m">utility_context_</a>);
  <a id='2617' tid='2618', class="m">Handle</a>&lt;<a id='2619' tid='2620', class="m">Object</a>&gt; <a id='2621' tid='2622', class="m">global</a> = <a id='2623' tid='2624', class="m">utility_context_</a>-&gt;<a id='2625' tid='2626', class="m">Global</a>();
  <a id='2627' tid='2628', class="m">Handle</a>&lt;<a id='2629' tid='2630', class="m">Value</a>&gt; <a id='2631' tid='2632', class="m">fun</a> = <a id='2633' tid='2634', class="m">global</a>-&gt;<a id='2635' tid='2636', class="m">Get</a>(<a id='2637' tid='2638', class="m">String</a><a id='2639' tid='2640', class="m">::</a><a id='2641' tid='2642', class="m">New</a>(<a id='2643' tid='2644', class="m">&quot;DebugCommandToJSONRequest&quot;</a>));
  <a id='2645' tid='2646', class="m">static</a> <a id='2647' tid='2648', class="m">const</a> <a id='2649' tid='2650', class="m">int</a> <a id='2651' tid='2652', class="m">kArgc</a> = <a id='2653' tid='2654', class="m">1</a>;
  <a id='2655' tid='2656', class="m">Handle</a>&lt;<a id='2657' tid='2658', class="m">Value</a>&gt; <a id='2659' tid='2660', class="m">argv</a>[<a id='2661' tid='2662', class="m">kArgc</a>] = { <a id='2663' tid='2664', class="m">command</a> };
  <a id='2665' tid='2666', class="m">Handle</a>&lt;<a id='2667' tid='2668', class="m">Value</a>&gt; <a id='2669' tid='2670', class="m">val</a> = <a id='2671' tid='2672', class="m">Handle</a>&lt;<a id='2673' tid='2674', class="m">Function</a>&gt;<a id='2675' tid='2676', class="m">::</a><a id='2677' tid='2678', class="m">Cast</a>(<a id='2679' tid='2680', class="m">fun</a>)-&gt;<a id='2681' tid='2682', class="m">Call</a>(<a id='2683' tid='2684', class="m">global</a>, <a id='2685' tid='2686', class="m">kArgc</a>, <a id='2687' tid='2688', class="m">argv</a>);
  <a id='2689' tid='2690', class="m">return</a> <a id='2691' tid='2692', class="m">val</a>;
}
<span class="d">#endif</span>


<a id='2493' tid='2494', class="m">int32_t</a><a id='2495' tid='2496', class="m">*</a> <a id='2497' tid='2498', class="m">Counter</a><a id='2499' tid='2500', class="m">::</a><a id='2501' tid='2502', class="m">Bind</a>(<a id='2503' tid='2504', class="m">const</a> <a id='2505' tid='2506', class="m">char</a><a id='2507' tid='2508', class="m">*</a> <a id='2509' tid='2510', class="m">name</a>, <a id='2511' tid='2512', class="m">bool</a> <a id='2513' tid='2514', class="m">is_histogram</a>) {
  <a id='2515' tid='2516', class="m">int</a> <a id='2517' tid='2518', class="m">i</a>;
  <a id='2519' tid='2520', class="m">for</a> (<a id='2521' tid='2522', class="m">i</a> <a id='2523' tid='2524', class="m">=</a> <a id='2525' tid='2526', class="m">0</a>; <a id='2527' tid='2528', class="m">i</a> <a id='2529' tid='2530', class="m">&lt;</a> <a id='2531' tid='2532', class="m">kMaxNameSize</a> <a id='2533' tid='2534', class="m">-</a> <a id='2535' tid='2536', class="m">1</a> <a id='2537' tid='2538', class="m">&&</a> <a id='2539' tid='2540', class="m">name</a>[<a id='2541' tid='2542', class="m">i</a>]; <a id='2543' tid='2544', class="m">i</a><a id='2545' tid='2546', class="m">++</a>)
    <a id='2547' tid='2548', class="m">name_</a>[<a id='2549' tid='2550', class="m">i</a>] <a id='2551' tid='2552', class="m">=</a> <a id='2553' tid='2554', class="m">static_cast</a>&lt;<a id='2555' tid='2556', class="m">char</a>&gt;(<a id='2557' tid='2558', class="m">name</a>[<a id='2559' tid='2560', class="m">i</a>]);
  <a id='2561' tid='2562', class="m">name_</a>[<a id='2563' tid='2564', class="m">i</a>] <a id='2565' tid='2566', class="m">=</a> <a id='2567' tid='2568', class="m">&#39;\0&#39;</a>;
  <a id='2569' tid='2570', class="m">is_histogram_</a> <a id='2571' tid='2572', class="m">=</a> <a id='2573' tid='2574', class="m">is_histogram</a>;
  <a id='2575' tid='2576', class="m">return</a> <a id='2577' tid='2578', class="m">ptr</a>();
}


<a id='2449' tid='2450', class="m">void</a> <a id='2451' tid='2452', class="m">Counter</a><a id='2453' tid='2454', class="m">::</a><a id='2455' tid='2456', class="m">AddSample</a>(<a id='2457' tid='2458', class="m">int32_t</a> <a id='2459' tid='2460', class="m">sample</a>) {
  <a id='2461' tid='2462', class="m">count_</a><a id='2463' tid='2464', class="m">++</a>;
  <a id='2465' tid='2466', class="m">sample_total_</a> <a id='2467' tid='2468', class="m">+=</a> <a id='2469' tid='2470', class="m">sample</a>;
}


<a id='2393' tid='2394', class="m">CounterCollection</a><a id='2395' tid='2396', class="m">::</a><a id='2397' tid='2398', class="m">CounterCollection</a>() {
  <a id='2399' tid='2400', class="m">magic_number_</a> <a id='2401' tid='2402', class="m">=</a> <a id='2403' tid='2404', class="m">0xDEADFACE</a>;
  <a id='2405' tid='2406', class="m">max_counters_</a> <a id='2407' tid='2408', class="m">=</a> <a id='2409' tid='2410', class="m">kMaxCounters</a>;
  <a id='2411' tid='2412', class="m">max_name_size_</a> <a id='2413' tid='2414', class="m">=</a> <a id='2415' tid='2416', class="m">Counter</a><a id='2417' tid='2418', class="m">::</a><a id='2419' tid='2420', class="m">kMaxNameSize</a>;
  <a id='2421' tid='2422', class="m">counters_in_use_</a> <a id='2423' tid='2424', class="m">=</a> <a id='2425' tid='2426', class="m">0</a>;
}


<a id='2361' tid='2362', class="m">Counter</a><a id='2363' tid='2364', class="m">*</a> <a id='2365' tid='2366', class="m">CounterCollection</a><a id='2367' tid='2368', class="m">::</a><a id='2369' tid='2370', class="m">GetNextCounter</a>() {
  <a id='2371' tid='2372', class="m">if</a> (<a id='2373' tid='2374', class="m">counters_in_use_</a> <a id='2375' tid='2376', class="m">==</a> <a id='2377' tid='2378', class="m">kMaxCounters</a>) <a id='2379' tid='2380', class="m">return</a> <a id='2381' tid='2382', class="m">NULL</a>;
  <a id='2383' tid='2384', class="m">return</a> <a id='2385' tid='2386', class="m">&</a><a id='2387' tid='2388', class="m">counters_</a>[<a id='2389' tid='2390', class="m">counters_in_use_</a><a id='2391' tid='2392', class="m">++</a>];
}


<a id='2245' tid='2246', class="m">void</a> <a id='2247' tid='2248', class="m">Shell</a><a id='2249' tid='2250', class="m">::</a><a id='2251' tid='2252', class="m">MapCounters</a>(<a id='2253' tid='2254', class="m">const</a> <a id='2255' tid='2256', class="m">char</a><a id='2257' tid='2258', class="m">*</a> <a id='2259' tid='2260', class="m">name</a>) {
  <a id='2261' tid='2262', class="m">counters_file_</a> <a id='2263' tid='2264', class="m">=</a> <a id='2265' tid='2266', class="m">i</a><a id='2267' tid='2268', class="m">::</a><a id='2269' tid='2270', class="m">OS</a><a id='2271' tid='2272', class="m">::</a><a id='2273' tid='2274', class="m">MemoryMappedFile</a><a id='2275' tid='2276', class="m">::</a><a id='2277' tid='2278', class="m">create</a>(<a id='2279' tid='2280', class="m">name</a>,
    <a id='2281' tid='2282', class="m">sizeof</a>(<a id='2283' tid='2284', class="m">CounterCollection</a>), <a id='2285' tid='2286', class="m">&</a><a id='2287' tid='2288', class="m">local_counters_</a>);
  <a id='2289' tid='2290', class="m">void</a><a id='2291' tid='2292', class="m">*</a> <a id='2293' tid='2294', class="m">memory</a> = (<a id='2295' tid='2296', class="m">counters_file_</a> <a id='2297' tid='2298', class="m">==</a> <a id='2299' tid='2300', class="m">NULL</a>) ?
      <a id='2301' tid='2302', class="m">NULL</a> : <a id='2303' tid='2304', class="m">counters_file_</a>-&gt;<a id='2305' tid='2306', class="m">memory</a>();
  <a id='2307' tid='2308', class="m">if</a> (<a id='2309' tid='2310', class="m">memory</a> <a id='2311' tid='2312', class="m">==</a> <a id='2313' tid='2314', class="m">NULL</a>) {
    <a id='2315' tid='2316', class="m">printf</a>(<a id='2317' tid='2318', class="m">&quot;Could not map counters file %s\n&quot;</a>, <a id='2319' tid='2320', class="m">name</a>);
    <a id='2321' tid='2322', class="m">exit</a>(<a id='2323' tid='2324', class="m">1</a>);
  }
  <a id='2325' tid='2326', class="m">counters_</a> <a id='2327' tid='2328', class="m">=</a> <a id='2329' tid='2330', class="m">static_cast</a>&lt;<a id='2331' tid='2332', class="m">CounterCollection</a><a id='2333' tid='2334', class="m">*</a>&gt;(<a id='2335' tid='2336', class="m">memory</a>);
  <a id='2337' tid='2338', class="m">V8</a><a id='2339' tid='2340', class="m">::</a><a id='2341' tid='2342', class="m">SetCounterFunction</a>(<a id='2343' tid='2344', class="m">LookupCounter</a>);
  <a id='2345' tid='2346', class="m">V8</a><a id='2347' tid='2348', class="m">::</a><a id='2349' tid='2350', class="m">SetCreateHistogramFunction</a>(<a id='2351' tid='2352', class="m">CreateHistogram</a>);
  <a id='2353' tid='2354', class="m">V8</a><a id='2355' tid='2356', class="m">::</a><a id='2357' tid='2358', class="m">SetAddHistogramSampleFunction</a>(<a id='2359' tid='2360', class="m">AddHistogramSample</a>);
}


<a id='2183' tid='2184', class="m">int</a> <a id='2185' tid='2186', class="m">CounterMap</a><a id='2187' tid='2188', class="m">::</a><a id='2189' tid='2190', class="m">Hash</a>(<a id='2191' tid='2192', class="m">const</a> <a id='2193' tid='2194', class="m">char</a><a id='2195' tid='2196', class="m">*</a> <a id='2197' tid='2198', class="m">name</a>) {
  <a id='2199' tid='2200', class="m">int</a> <a id='2201' tid='2202', class="m">h</a> = <a id='2203' tid='2204', class="m">0</a>;
  <a id='2205' tid='2206', class="m">int</a> <a id='2207' tid='2208', class="m">c</a>;
  <a id='2209' tid='2210', class="m">while</a> ((<a id='2211' tid='2212', class="m">c</a> <a id='2213' tid='2214', class="m">=</a> <a id='2215' tid='2216', class="m">*</a><a id='2217' tid='2218', class="m">name</a><a id='2219' tid='2220', class="m">++</a>) <a id='2221' tid='2222', class="m">!=</a> <a id='2223' tid='2224', class="m">0</a>) {
    <a id='2225' tid='2226', class="m">h</a> <a id='2227' tid='2228', class="m">+=</a> <a id='2229' tid='2230', class="m">h</a> <a id='2231' tid='2232', class="m">&lt;&lt;</a> <a id='2233' tid='2234', class="m">5</a>;
    <a id='2235' tid='2236', class="m">h</a> <a id='2237' tid='2238', class="m">+=</a> <a id='2239' tid='2240', class="m">c</a>;
  }
  <a id='2241' tid='2242', class="m">return</a> <a id='2243' tid='2244', class="m">h</a>;
}


<a id='2093' tid='2094', class="m">Counter</a><a id='2095' tid='2096', class="m">*</a> <a id='2097' tid='2098', class="m">Shell</a><a id='2099' tid='2100', class="m">::</a><a id='2101' tid='2102', class="m">GetCounter</a>(<a id='2103' tid='2104', class="m">const</a> <a id='2105' tid='2106', class="m">char</a><a id='2107' tid='2108', class="m">*</a> <a id='2109' tid='2110', class="m">name</a>, <a id='2111' tid='2112', class="m">bool</a> <a id='2113' tid='2114', class="m">is_histogram</a>) {
  <a id='2115' tid='2116', class="m">Counter</a><a id='2117' tid='2118', class="m">*</a> <a id='2119' tid='2120', class="m">counter</a> = <a id='2121' tid='2122', class="m">counter_map_</a>-&gt;<a id='2123' tid='2124', class="m">Lookup</a>(<a id='2125' tid='2126', class="m">name</a>);

  <a id='2127' tid='2128', class="m">if</a> (<a id='2129' tid='2130', class="m">counter</a> <a id='2131' tid='2132', class="m">==</a> <a id='2133' tid='2134', class="m">NULL</a>) {
    <a id='2135' tid='2136', class="m">counter</a> <a id='2137' tid='2138', class="m">=</a> <a id='2139' tid='2140', class="m">counters_</a>-&gt;<a id='2141' tid='2142', class="m">GetNextCounter</a>();
    <a id='2143' tid='2144', class="m">if</a> (<a id='2145' tid='2146', class="m">counter</a> <a id='2147' tid='2148', class="m">!=</a> <a id='2149' tid='2150', class="m">NULL</a>) {
      <a id='2151' tid='2152', class="m">counter_map_</a>-&gt;<a id='2153' tid='2154', class="m">Set</a>(<a id='2155' tid='2156', class="m">name</a>, <a id='2157' tid='2158', class="m">counter</a>);
      <a id='2159' tid='2160', class="m">counter</a>-&gt;<a id='2161' tid='2162', class="m">Bind</a>(<a id='2163' tid='2164', class="m">name</a>, <a id='2165' tid='2166', class="m">is_histogram</a>);
    }
  } <a id='2167' tid='2168', class="m">else</a> {
    <a id='2169' tid='2170', class="m">ASSERT</a>(<a id='2171' tid='2172', class="m">counter</a>-&gt;<a id='2173' tid='2174', class="m">is_histogram</a>() <a id='2175' tid='2176', class="m">==</a> <a id='2177' tid='2178', class="m">is_histogram</a>);
  }
  <a id='2179' tid='2180', class="m">return</a> <a id='2181' tid='2182', class="m">counter</a>;
}


<a id='2043' tid='2044', class="m">int</a><a id='2045' tid='2046', class="m">*</a> <a id='2047' tid='2048', class="m">Shell</a><a id='2049' tid='2050', class="m">::</a><a id='2051' tid='2052', class="m">LookupCounter</a>(<a id='2053' tid='2054', class="m">const</a> <a id='2055' tid='2056', class="m">char</a><a id='2057' tid='2058', class="m">*</a> <a id='2059' tid='2060', class="m">name</a>) {
  <a id='2061' tid='2062', class="m">Counter</a><a id='2063' tid='2064', class="m">*</a> <a id='2065' tid='2066', class="m">counter</a> = <a id='2067' tid='2068', class="m">GetCounter</a>(<a id='2069' tid='2070', class="m">name</a>, <a id='2071' tid='2072', class="m">false</a>);

  <a id='2073' tid='2074', class="m">if</a> (<a id='2075' tid='2076', class="m">counter</a> <a id='2077' tid='2078', class="m">!=</a> <a id='2079' tid='2080', class="m">NULL</a>) {
    <a id='2081' tid='2082', class="m">return</a> <a id='2083' tid='2084', class="m">counter</a>-&gt;<a id='2085' tid='2086', class="m">ptr</a>();
  } <a id='2087' tid='2088', class="m">else</a> {
    <a id='2089' tid='2090', class="m">return</a> <a id='2091' tid='2092', class="m">NULL</a>;
  }
}


<a id='2005' tid='2006', class="m">void</a><a id='2007' tid='2008', class="m">*</a> <a id='2009' tid='2010', class="m">Shell</a><a id='2011' tid='2012', class="m">::</a><a id='2013' tid='2014', class="m">CreateHistogram</a>(<a id='2015' tid='2016', class="m">const</a> <a id='2017' tid='2018', class="m">char</a><a id='2019' tid='2020', class="m">*</a> <a id='2021' tid='2022', class="m">name</a>,
                             <a id='2023' tid='2024', class="m">int</a> <a id='2025' tid='2026', class="m">min</a>,
                             <a id='2027' tid='2028', class="m">int</a> <a id='2029' tid='2030', class="m">max</a>,
                             <a id='2031' tid='2032', class="m">size_t</a> <a id='2033' tid='2034', class="m">buckets</a>) {
  <a id='2035' tid='2036', class="m">return</a> <a id='2037' tid='2038', class="m">GetCounter</a>(<a id='2039' tid='2040', class="m">name</a>, <a id='2041' tid='2042', class="m">true</a>);
}


<a id='1967' tid='1968', class="m">void</a> <a id='1969' tid='1970', class="m">Shell</a><a id='1971' tid='1972', class="m">::</a><a id='1973' tid='1974', class="m">AddHistogramSample</a>(<a id='1975' tid='1976', class="m">void</a><a id='1977' tid='1978', class="m">*</a> <a id='1979' tid='1980', class="m">histogram</a>, <a id='1981' tid='1982', class="m">int</a> <a id='1983' tid='1984', class="m">sample</a>) {
  <a id='1985' tid='1986', class="m">Counter</a><a id='1987' tid='1988', class="m">*</a> <a id='1989' tid='1990', class="m">counter</a> = <a id='1991' tid='1992', class="m">reinterpret_cast</a>&lt;<a id='1993' tid='1994', class="m">Counter</a><a id='1995' tid='1996', class="m">*</a>&gt;(<a id='1997' tid='1998', class="m">histogram</a>);
  <a id='1999' tid='2000', class="m">counter</a>-&gt;<a id='2001' tid='2002', class="m">AddSample</a>(<a id='2003' tid='2004', class="m">sample</a>);
}


<span class="d">void</span> <span class="d">Shell::Initialize</span><span class="d">()</span> {
  <a id='1043' tid='1044', class="m">Shell</a><a id='1045' tid='1046', class="m">::</a><a id='1047' tid='1048', class="m">counter_map_</a> <a id='1049' tid='1050', class="m">=</a> <a id='1051' tid='1052', class="m">new</a> <a id='1053' tid='1054', class="m">CounterMap</a>();
  // Set up counters
  <span class="d">if (i::FLAG_map_counters != NULL)
    MapCounters(i::FLAG_map_counters);</span>
  <a id='181' tid='182', class="m">if</a> (<a id='183' tid='184', class="m">i</a><a id='185' tid='186', class="m">::</a><a id='187' tid='188', class="m">FLAG_dump_counters</a>) {
    <a id='189' tid='190', class="m">V8</a><a id='191' tid='192', class="m">::</a><a id='193' tid='194', class="m">SetCounterFunction</a>(<a id='195' tid='196', class="m">LookupCounter</a>);
    <a id='197' tid='198', class="m">V8</a><a id='199' tid='200', class="m">::</a><a id='201' tid='202', class="m">SetCreateHistogramFunction</a>(<a id='203' tid='204', class="m">CreateHistogram</a>);
    <a id='205' tid='206', class="m">V8</a><a id='207' tid='208', class="m">::</a><a id='209' tid='210', class="m">SetAddHistogramSampleFunction</a>(<a id='211' tid='212', class="m">AddHistogramSample</a>);
  }

  // Initialize the global objects
  <span class="d">HandleScope scope;</span>
  <span class="d">Handle&lt;ObjectTemplate&gt; global_template = ObjectTemplate::New();</span>
  <a id='1903' tid='1904', class="m">global_template</a>-&gt;<a id='1905' tid='1906', class="m">Set</a>(<a id='1907' tid='1908', class="m">String</a><a id='1909' tid='1910', class="m">::</a><a id='1911' tid='1912', class="m">New</a>(<a id='1913' tid='1914', class="m">&quot;print&quot;</a>), <a id='1915' tid='1916', class="m">FunctionTemplate</a><a id='1917' tid='1918', class="m">::</a><a id='1919' tid='1920', class="m">New</a>(<a id='1921' tid='1922', class="m">Print</a>));
  <a id='1751' tid='1752', class="m">global_template</a>-&gt;<a id='1753' tid='1754', class="m">Set</a>(<a id='1755' tid='1756', class="m">String</a><a id='1757' tid='1758', class="m">::</a><a id='1759' tid='1760', class="m">New</a>(<a id='1761' tid='1762', class="m">&quot;write&quot;</a>), <a id='1763' tid='1764', class="m">FunctionTemplate</a><a id='1765' tid='1766', class="m">::</a><a id='1767' tid='1768', class="m">New</a>(<a id='1769' tid='1770', class="m">Write</a>));
  <a id='1491' tid='1492', class="m">global_template</a>-&gt;<a id='1493' tid='1494', class="m">Set</a>(<a id='1495' tid='1496', class="m">String</a><a id='1497' tid='1498', class="m">::</a><a id='1499' tid='1500', class="m">New</a>(<a id='1501' tid='1502', class="m">&quot;read&quot;</a>), <a id='1503' tid='1504', class="m">FunctionTemplate</a><a id='1505' tid='1506', class="m">::</a><a id='1507' tid='1508', class="m">New</a>(<a id='1509' tid='1510', class="m">Read</a>));
  <a id='1397' tid='1398', class="m">global_template</a>-&gt;<a id='1399' tid='1400', class="m">Set</a>(<a id='1401' tid='1402', class="m">String</a><a id='1403' tid='1404', class="m">::</a><a id='1405' tid='1406', class="m">New</a>(<a id='1407' tid='1408', class="m">&quot;readline&quot;</a>),
                       <a id='1409' tid='1410', class="m">FunctionTemplate</a><a id='1411' tid='1412', class="m">::</a><a id='1413' tid='1414', class="m">New</a>(<a id='1415' tid='1416', class="m">ReadLine</a>));
  <a id='1303' tid='1304', class="m">global_template</a>-&gt;<a id='1305' tid='1306', class="m">Set</a>(<a id='1307' tid='1308', class="m">String</a><a id='1309' tid='1310', class="m">::</a><a id='1311' tid='1312', class="m">New</a>(<a id='1313' tid='1314', class="m">&quot;load&quot;</a>), <a id='1315' tid='1316', class="m">FunctionTemplate</a><a id='1317' tid='1318', class="m">::</a><a id='1319' tid='1320', class="m">New</a>(<a id='1321' tid='1322', class="m">Load</a>));
  <a id='1085' tid='1086', class="m">global_template</a>-&gt;<a id='1087' tid='1088', class="m">Set</a>(<a id='1089' tid='1090', class="m">String</a><a id='1091' tid='1092', class="m">::</a><a id='1093' tid='1094', class="m">New</a>(<a id='1095' tid='1096', class="m">&quot;quit&quot;</a>), <a id='1097' tid='1098', class="m">FunctionTemplate</a><a id='1099' tid='1100', class="m">::</a><a id='1101' tid='1102', class="m">New</a>(<a id='1103' tid='1104', class="m">Quit</a>));
  <a id='437' tid='438', class="m">global_template</a>-&gt;<a id='439' tid='440', class="m">Set</a>(<a id='441' tid='442', class="m">String</a><a id='443' tid='444', class="m">::</a><a id='445' tid='446', class="m">New</a>(<a id='447' tid='448', class="m">&quot;version&quot;</a>), <a id='449' tid='450', class="m">FunctionTemplate</a><a id='451' tid='452', class="m">::</a><a id='453' tid='454', class="m">New</a>(<a id='455' tid='456', class="m">Version</a>));

  <a id='263' tid='264', class="m">Handle</a>&lt;<a id='265' tid='266', class="m">ObjectTemplate</a>&gt; <a id='267' tid='268', class="m">os_templ</a> = <a id='269' tid='270', class="m">ObjectTemplate</a><a id='271' tid='272', class="m">::</a><a id='273' tid='274', class="m">New</a>();
  <span class="d">AddOSMethods(os_templ);</span>
  <a id='249' tid='250', class="m">global_template</a>-&gt;<a id='251' tid='252', class="m">Set</a>(<a id='253' tid='254', class="m">String</a><a id='255' tid='256', class="m">::</a><a id='257' tid='258', class="m">New</a>(<a id='259' tid='260', class="m">&quot;os&quot;</a>), <a id='261' tid='262', class="m">os_templ</a>);

  <span class="d">utility_context_</span> <span class="d">=</span> <a id='953' tid='954', class="m">Context</a><a id='955' tid='956', class="m">::</a><a id='957' tid='958', class="m">New</a>(<a id='959' tid='960', class="m">NULL</a>, <a id='961' tid='962', class="m">global_template</a>);
  <span class="d">utility_context_-&gt;SetSecurityToken(Undefined());</span>
  <a id='1957' tid='1958', class="m">Context</a><a id='1959' tid='1960', class="m">::</a><a id='1961' tid='1962', class="m">Scope</a> <a id='1963' tid='1964', class="m">utility_scope</a>(<a id='1965' tid='1966', class="m">utility_context_</a>);

  <a id='167' tid='168', class="m">i</a><a id='169' tid='170', class="m">::</a><a id='171' tid='172', class="m">JSArguments</a> <a id='173' tid='174', class="m">js_args</a> = <a id='175' tid='176', class="m">i</a><a id='177' tid='178', class="m">::</a><a id='179' tid='180', class="m">FLAG_js_arguments</a>;
  <a id='137' tid='138', class="m">i</a><a id='139' tid='140', class="m">::</a><a id='141' tid='142', class="m">Handle</a>&lt;<a id='143' tid='144', class="m">i</a><a id='145' tid='146', class="m">::</a><a id='147' tid='148', class="m">FixedArray</a>&gt; <span class="d">arguments_array =
      i::Factory::NewFixedArray(js_args.argc())</span>;
  <a id='29' tid='30', class="m">for</a> (<a id='31' tid='32', class="m">int</a> <a id='33' tid='34', class="m">j</a> = <a id='35' tid='36', class="m">0</a>; <a id='37' tid='38', class="m">j</a> <a id='39' tid='40', class="m">&lt;</a> <a id='41' tid='42', class="m">js_args</a>.<a id='43' tid='44', class="m">argc</a>(); <a id='45' tid='46', class="m">j</a><a id='47' tid='48', class="m">++</a>) {
    <a id='49' tid='50', class="m">i</a><a id='51' tid='52', class="m">::</a><a id='53' tid='54', class="m">Handle</a>&lt;<a id='55' tid='56', class="m">i</a><a id='57' tid='58', class="m">::</a><a id='59' tid='60', class="m">String</a>&gt; <a id='61' tid='62', class="m">arg</a> =
        <span class="d">i::Factory::NewStringFromUtf8</span>(<a id='63' tid='64', class="m">i</a><a id='65' tid='66', class="m">::</a><a id='67' tid='68', class="m">CStrVector</a>(<a id='69' tid='70', class="m">js_args</a>[<a id='71' tid='72', class="m">j</a>]));
    <a id='73' tid='74', class="m">arguments_array</a>-&gt;<a id='75' tid='76', class="m">set</a>(<a id='77' tid='78', class="m">j</a>, <a id='79' tid='80', class="m">*</a><a id='81' tid='82', class="m">arg</a>);
  }
  <a id='17' tid='18', class="m">i</a><a id='19' tid='20', class="m">::</a><a id='21' tid='22', class="m">Handle</a>&lt;<a id='23' tid='24', class="m">i</a><a id='25' tid='26', class="m">::</a><a id='27' tid='28', class="m">JSArray</a>&gt; <span class="d">arguments_jsarray =
      i::Factory::NewJSArrayWithElements(arguments_array)</span>;
  <span class="d">global_template-&gt;Set</span>(<a id='1' tid='2', class="m">String</a><a id='3' tid='4', class="m">::</a><a id='5' tid='6', class="m">New</a>(<a id='7' tid='8', class="m">&quot;arguments&quot;</a>),
                       <a id='9' tid='10', class="m">Utils</a><a id='11' tid='12', class="m">::</a><a id='13' tid='14', class="m">ToLocal</a>(<a id='15' tid='16', class="m">arguments_jsarray</a>));

<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
  // Install the debugger object in the utility scope
  <span class="d">i::Debug::Load();</span>
  <span class="d">i::JSObject* debug = i::Debug::debug_context()-&gt;global();</span>
  <span class="d">utility_context_-&gt;Global()-&gt;Set(String::New(&quot;$debug&quot;),
                                  Utils::ToLocal(&debug));</span>
<span class="d">#endif</span>

  // Run the d8 shell utility script in the utility context
  <a id='1935' tid='1936', class="m">int</a> <a id='1937' tid='1938', class="m">source_index</a> = <a id='1939' tid='1940', class="m">i</a><a id='1941' tid='1942', class="m">::</a><a id='1943' tid='1944', class="m">NativesCollection</a>&lt;<a id='1945' tid='1946', class="m">i</a><a id='1947' tid='1948', class="m">::</a><a id='1949' tid='1950', class="m">D8</a>&gt;<a id='1951' tid='1952', class="m">::</a><a id='1953' tid='1954', class="m">GetIndex</a>(<a id='1955' tid='1956', class="m">&quot;d8&quot;</a>);
  <a id='1577' tid='1578', class="m">i</a><a id='1579' tid='1580', class="m">::</a><a id='1581' tid='1582', class="m">Vector</a>&lt;<a id='1583' tid='1584', class="m">const</a> <a id='1585' tid='1586', class="m">char</a>&gt; <span class="d">shell_source
      = i::NativesCollection&lt;i::D8&gt;::GetScriptSource(source_index)</span>;
  <a id='1439' tid='1440', class="m">i</a><a id='1441' tid='1442', class="m">::</a><a id='1443' tid='1444', class="m">Vector</a>&lt;<a id='1445' tid='1446', class="m">const</a> <a id='1447' tid='1448', class="m">char</a>&gt; <a id='1449' tid='1450', class="m">shell_source_name</a>
      = <a id='1451' tid='1452', class="m">i</a><a id='1453' tid='1454', class="m">::</a><a id='1455' tid='1456', class="m">NativesCollection</a>&lt;<a id='1457' tid='1458', class="m">i</a><a id='1459' tid='1460', class="m">::</a><a id='1461' tid='1462', class="m">D8</a>&gt;<a id='1463' tid='1464', class="m">::</a><a id='1465' tid='1466', class="m">GetScriptName</a>(<a id='1467' tid='1468', class="m">source_index</a>);
  <a id='1249' tid='1250', class="m">Handle</a>&lt;<a id='1251' tid='1252', class="m">String</a>&gt; <a id='1253' tid='1254', class="m">source</a> = <a id='1255' tid='1256', class="m">String</a><a id='1257' tid='1258', class="m">::</a><a id='1259' tid='1260', class="m">New</a>(<a id='1261' tid='1262', class="m">shell_source</a>.<a id='1263' tid='1264', class="m">start</a>(),
                                      <a id='1265' tid='1266', class="m">shell_source</a>.<a id='1267' tid='1268', class="m">length</a>());
  <a id='555' tid='556', class="m">Handle</a>&lt;<a id='557' tid='558', class="m">String</a>&gt; <a id='559' tid='560', class="m">name</a> = <a id='561' tid='562', class="m">String</a><a id='563' tid='564', class="m">::</a><a id='565' tid='566', class="m">New</a>(<a id='567' tid='568', class="m">shell_source_name</a>.<a id='569' tid='570', class="m">start</a>(),
                                    <a id='571' tid='572', class="m">shell_source_name</a>.<a id='573' tid='574', class="m">length</a>());
  <a id='313' tid='314', class="m">Handle</a>&lt;<a id='315' tid='316', class="m">Script</a>&gt; <a id='317' tid='318', class="m">script</a> = <a id='319' tid='320', class="m">Script</a><a id='321' tid='322', class="m">::</a><a id='323' tid='324', class="m">Compile</a>(<a id='325' tid='326', class="m">source</a>, <a id='327' tid='328', class="m">name</a>);
  <span class="d">script-&gt;Run();</span>

  // Mark the d8 shell script as native to avoid it showing up as normal source
  // in the debugger.
  <span class="d">i::Handle&lt;i::JSFunction&gt;</span> <span class="d">script_fun</span> = <a id='285' tid='286', class="m">Utils</a><a id='287' tid='288', class="m">::</a><a id='289' tid='290', class="m">OpenHandle</a>(<a id='291' tid='292', class="m">*</a><a id='293' tid='294', class="m">script</a>);
  <a id='213' tid='214', class="m">i</a><a id='215' tid='216', class="m">::</a><a id='217' tid='218', class="m">Handle</a>&lt;<a id='219' tid='220', class="m">i</a><a id='221' tid='222', class="m">::</a><a id='223' tid='224', class="m">Script</a>&gt; <a id='225' tid='226', class="m">script_object</a> =
      <a id='227' tid='228', class="m">i</a><a id='229' tid='230', class="m">::</a><a id='231' tid='232', class="m">Handle</a>&lt;<a id='233' tid='234', class="m">i</a><a id='235' tid='236', class="m">::</a><a id='237' tid='238', class="m">Script</a>&gt;(<a id='239' tid='240', class="m">i</a><a id='241' tid='242', class="m">::</a><a id='243' tid='244', class="m">Script</a><a id='245' tid='246', class="m">::</a><a id='247' tid='248', class="m">cast</a><span class="d">(script_fun-&gt;shared()-&gt;script())</span>);
  <a id='113' tid='114', class="m">script_object</a>-&gt;<a id='115' tid='116', class="m">set_type</a>(<a id='117' tid='118', class="m">i</a><a id='119' tid='120', class="m">::</a><a id='121' tid='122', class="m">Smi</a><a id='123' tid='124', class="m">::</a><a id='125' tid='126', class="m">FromInt</a>(<a id='127' tid='128', class="m">i</a><a id='129' tid='130', class="m">::</a><a id='131' tid='132', class="m">Script</a><a id='133' tid='134', class="m">::</a><a id='135' tid='136', class="m">TYPE_NATIVE</a>));

  // Create the evaluation context
  <span class="d">evaluation_context_</span> <span class="d">=</span> <a id='637' tid='638', class="m">Context</a><a id='639' tid='640', class="m">::</a><a id='641' tid='642', class="m">New</a>(<a id='643' tid='644', class="m">NULL</a>, <a id='645' tid='646', class="m">global_template</a>);
  <span class="d">evaluation_context_-&gt;SetSecurityToken(Undefined());</span>

<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
  // Set the security token of the debug context to allow access.
  <span class="d">i::Debug::debug_context()-&gt;set_security_token(i::Heap::undefined_value());</span>

  // Start the debugger agent if requested.
  <a id='149' tid='150', class="m">if</a> (<a id='151' tid='152', class="m">i</a><a id='153' tid='154', class="m">::</a><a id='155' tid='156', class="m">FLAG_debugger_agent</a>) {
    <a id='157' tid='158', class="m">v8</a><a id='159' tid='160', class="m">::</a><a id='161' tid='162', class="m">Debug</a><a id='163' tid='164', class="m">::</a><a id='165' tid='166', class="m">EnableAgent</a><span class="d">(&quot;d8 shell&quot;, i::FLAG_debugger_port)</span>;
  }

  // Start the in-process debugger if requested.
  <a id='83' tid='84', class="m">if</a> (<a id='85' tid='86', class="m">i</a><a id='87' tid='88', class="m">::</a><a id='89' tid='90', class="m">FLAG_debugger</a> <a id='91' tid='92', class="m">&&</a> <a id='93' tid='94', class="m">!</a><a id='95' tid='96', class="m">i</a><a id='97' tid='98', class="m">::</a><a id='99' tid='100', class="m">FLAG_debugger_agent</a>) {
    <a id='101' tid='102', class="m">v8</a><a id='103' tid='104', class="m">::</a><a id='105' tid='106', class="m">Debug</a><a id='107' tid='108', class="m">::</a><a id='109' tid='110', class="m">SetDebugEventListener</a>(<a id='111' tid='112', class="m">HandleDebugEvent</a>);
  }
<span class="d">#endif</span>
}


<a id='1771' tid='1772', class="m">void</a> <a id='1773' tid='1774', class="m">Shell</a><a id='1775' tid='1776', class="m">::</a><a id='1777' tid='1778', class="m">OnExit</a>() {
  <a id='1779' tid='1780', class="m">if</a> (<a id='1781' tid='1782', class="m">i</a><a id='1783' tid='1784', class="m">::</a><a id='1785' tid='1786', class="m">FLAG_dump_counters</a>) {
    <a id='1787' tid='1788', class="m">::</a><a id='1789' tid='1790', class="m">printf</a>(<a id='1791' tid='1792', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
    <a id='1793' tid='1794', class="m">::</a><a id='1795' tid='1796', class="m">printf</a>(<a id='1797' tid='1798', class="m">&quot;| Name                                   | Value       |\n&quot;</a>);
    <a id='1799' tid='1800', class="m">::</a><a id='1801' tid='1802', class="m">printf</a>(<a id='1803' tid='1804', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
    <a id='1805' tid='1806', class="m">for</a> (<a id='1807' tid='1808', class="m">CounterMap</a><a id='1809' tid='1810', class="m">::</a><a id='1811' tid='1812', class="m">Iterator</a> <a id='1813' tid='1814', class="m">i</a>(<a id='1815' tid='1816', class="m">counter_map_</a>); <a id='1817' tid='1818', class="m">i</a>.<a id='1819' tid='1820', class="m">More</a>(); <a id='1821' tid='1822', class="m">i</a>.<a id='1823' tid='1824', class="m">Next</a>()) {
      <a id='1825' tid='1826', class="m">Counter</a><a id='1827' tid='1828', class="m">*</a> <a id='1829' tid='1830', class="m">counter</a> = <a id='1831' tid='1832', class="m">i</a>.<a id='1833' tid='1834', class="m">CurrentValue</a>();
      <a id='1835' tid='1836', class="m">if</a> (<a id='1837' tid='1838', class="m">counter</a>-&gt;<a id='1839' tid='1840', class="m">is_histogram</a>()) {
        <a id='1841' tid='1842', class="m">::</a><a id='1843' tid='1844', class="m">printf</a>(<a id='1845' tid='1846', class="m">&quot;| c:%-36s | %11i |\n&quot;</a>, <a id='1847' tid='1848', class="m">i</a>.<a id='1849' tid='1850', class="m">CurrentKey</a>(), <a id='1851' tid='1852', class="m">counter</a>-&gt;<a id='1853' tid='1854', class="m">count</a>());
        <a id='1855' tid='1856', class="m">::</a><a id='1857' tid='1858', class="m">printf</a>(<a id='1859' tid='1860', class="m">&quot;| t:%-36s | %11i |\n&quot;</a>,
                 <a id='1861' tid='1862', class="m">i</a>.<a id='1863' tid='1864', class="m">CurrentKey</a>(),
                 <a id='1865' tid='1866', class="m">counter</a>-&gt;<a id='1867' tid='1868', class="m">sample_total</a>());
      } <a id='1869' tid='1870', class="m">else</a> {
        <a id='1871' tid='1872', class="m">::</a><a id='1873' tid='1874', class="m">printf</a>(<a id='1875' tid='1876', class="m">&quot;| %-38s | %11i |\n&quot;</a>, <a id='1877' tid='1878', class="m">i</a>.<a id='1879' tid='1880', class="m">CurrentKey</a>(), <a id='1881' tid='1882', class="m">counter</a>-&gt;<a id='1883' tid='1884', class="m">count</a>());
      }
    }
    <a id='1885' tid='1886', class="m">::</a><a id='1887' tid='1888', class="m">printf</a>(<a id='1889' tid='1890', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
  }
  <a id='1891' tid='1892', class="m">if</a> (<a id='1893' tid='1894', class="m">counters_file_</a> <a id='1895' tid='1896', class="m">!=</a> <a id='1897' tid='1898', class="m">NULL</a>)
    <a id='1899' tid='1900', class="m">delete</a> <a id='1901' tid='1902', class="m">counters_file_</a>;
}


<a id='1587' tid='1588', class="m">static</a> <a id='1589' tid='1590', class="m">char</a><a id='1591' tid='1592', class="m">*</a> <a id='1593' tid='1594', class="m">ReadChars</a>(<a id='1595' tid='1596', class="m">const</a> <a id='1597' tid='1598', class="m">char</a><a id='1599' tid='1600', class="m">*</a> <a id='1601' tid='1602', class="m">name</a>, <a id='1603' tid='1604', class="m">int</a><a id='1605' tid='1606', class="m">*</a> <a id='1607' tid='1608', class="m">size_out</a>) {
  <a id='1609' tid='1610', class="m">v8</a><a id='1611' tid='1612', class="m">::</a><a id='1613' tid='1614', class="m">Unlocker</a> <a id='1615' tid='1616', class="m">unlocker</a>;  // Release the V8 lock while reading files.
  <a id='1617' tid='1618', class="m">FILE</a><a id='1619' tid='1620', class="m">*</a> <a id='1621' tid='1622', class="m">file</a> = <a id='1623' tid='1624', class="m">i</a><a id='1625' tid='1626', class="m">::</a><a id='1627' tid='1628', class="m">OS</a><a id='1629' tid='1630', class="m">::</a><a id='1631' tid='1632', class="m">FOpen</a>(<a id='1633' tid='1634', class="m">name</a>, <a id='1635' tid='1636', class="m">&quot;rb&quot;</a>);
  <a id='1637' tid='1638', class="m">if</a> (<a id='1639' tid='1640', class="m">file</a> <a id='1641' tid='1642', class="m">==</a> <a id='1643' tid='1644', class="m">NULL</a>) <a id='1645' tid='1646', class="m">return</a> <a id='1647' tid='1648', class="m">NULL</a>;

  <a id='1649' tid='1650', class="m">fseek</a>(<a id='1651' tid='1652', class="m">file</a>, <a id='1653' tid='1654', class="m">0</a>, <a id='1655' tid='1656', class="m">SEEK_END</a>);
  <a id='1657' tid='1658', class="m">int</a> <a id='1659' tid='1660', class="m">size</a> = <a id='1661' tid='1662', class="m">ftell</a>(<a id='1663' tid='1664', class="m">file</a>);
  <a id='1665' tid='1666', class="m">rewind</a>(<a id='1667' tid='1668', class="m">file</a>);

  <a id='1669' tid='1670', class="m">char</a><a id='1671' tid='1672', class="m">*</a> <a id='1673' tid='1674', class="m">chars</a> = <a id='1675' tid='1676', class="m">new</a> <a id='1677' tid='1678', class="m">char</a>[<a id='1679' tid='1680', class="m">size</a> <a id='1681' tid='1682', class="m">+</a> <a id='1683' tid='1684', class="m">1</a>];
  <a id='1685' tid='1686', class="m">chars</a>[<a id='1687' tid='1688', class="m">size</a>] <a id='1689' tid='1690', class="m">=</a> <a id='1691' tid='1692', class="m">&#39;\0&#39;</a>;
  <a id='1693' tid='1694', class="m">for</a> (<a id='1695' tid='1696', class="m">int</a> <a id='1697' tid='1698', class="m">i</a> = <a id='1699' tid='1700', class="m">0</a>; <a id='1701' tid='1702', class="m">i</a> <a id='1703' tid='1704', class="m">&lt;</a> <a id='1705' tid='1706', class="m">size</a>;) {
    <a id='1707' tid='1708', class="m">int</a> <a id='1709' tid='1710', class="m">read</a> = <a id='1711' tid='1712', class="m">fread</a>(<a id='1713' tid='1714', class="m">&</a><a id='1715' tid='1716', class="m">chars</a>[<a id='1717' tid='1718', class="m">i</a>], <a id='1719' tid='1720', class="m">1</a>, <a id='1721' tid='1722', class="m">size</a> <a id='1723' tid='1724', class="m">-</a> <a id='1725' tid='1726', class="m">i</a>, <a id='1727' tid='1728', class="m">file</a>);
    <a id='1729' tid='1730', class="m">i</a> <a id='1731' tid='1732', class="m">+=</a> <a id='1733' tid='1734', class="m">read</a>;
  }
  <a id='1735' tid='1736', class="m">fclose</a>(<a id='1737' tid='1738', class="m">file</a>);
  <a id='1739' tid='1740', class="m">*</a><a id='1741' tid='1742', class="m">size_out</a> <a id='1743' tid='1744', class="m">=</a> <a id='1745' tid='1746', class="m">size</a>;
  <a id='1747' tid='1748', class="m">return</a> <a id='1749' tid='1750', class="m">chars</a>;
}


<a id='1511' tid='1512', class="m">static</a> <a id='1513' tid='1514', class="m">char</a><a id='1515' tid='1516', class="m">*</a> <a id='1517' tid='1518', class="m">ReadToken</a>(<a id='1519' tid='1520', class="m">char</a><a id='1521' tid='1522', class="m">*</a> <a id='1523' tid='1524', class="m">data</a>, <a id='1525' tid='1526', class="m">char</a> <a id='1527' tid='1528', class="m">token</a>) {
  <a id='1529' tid='1530', class="m">char</a><a id='1531' tid='1532', class="m">*</a> <a id='1533' tid='1534', class="m">next</a> = <a id='1535' tid='1536', class="m">i</a><a id='1537' tid='1538', class="m">::</a><a id='1539' tid='1540', class="m">OS</a><a id='1541' tid='1542', class="m">::</a><a id='1543' tid='1544', class="m">StrChr</a>(<a id='1545' tid='1546', class="m">data</a>, <a id='1547' tid='1548', class="m">token</a>);
  <a id='1549' tid='1550', class="m">if</a> (<a id='1551' tid='1552', class="m">next</a> <a id='1553' tid='1554', class="m">!=</a> <a id='1555' tid='1556', class="m">NULL</a>) {
    <a id='1557' tid='1558', class="m">*</a><a id='1559' tid='1560', class="m">next</a> <a id='1561' tid='1562', class="m">=</a> <a id='1563' tid='1564', class="m">&#39;\0&#39;</a>;
    <a id='1565' tid='1566', class="m">return</a> (<a id='1567' tid='1568', class="m">next</a> <a id='1569' tid='1570', class="m">+</a> <a id='1571' tid='1572', class="m">1</a>);
  }

  <a id='1573' tid='1574', class="m">return</a> <a id='1575' tid='1576', class="m">NULL</a>;
}


<a id='1469' tid='1470', class="m">static</a> <a id='1471' tid='1472', class="m">char</a><a id='1473' tid='1474', class="m">*</a> <a id='1475' tid='1476', class="m">ReadLine</a>(<a id='1477' tid='1478', class="m">char</a><a id='1479' tid='1480', class="m">*</a> <a id='1481' tid='1482', class="m">data</a>) {
  <a id='1483' tid='1484', class="m">return</a> <a id='1485' tid='1486', class="m">ReadToken</a>(<a id='1487' tid='1488', class="m">data</a>, <a id='1489' tid='1490', class="m">&#39;\n&#39;</a>);
}


<a id='1417' tid='1418', class="m">static</a> <a id='1419' tid='1420', class="m">char</a><a id='1421' tid='1422', class="m">*</a> <a id='1423' tid='1424', class="m">ReadWord</a>(<a id='1425' tid='1426', class="m">char</a><a id='1427' tid='1428', class="m">*</a> <a id='1429' tid='1430', class="m">data</a>) {
  <a id='1431' tid='1432', class="m">return</a> <a id='1433' tid='1434', class="m">ReadToken</a>(<a id='1435' tid='1436', class="m">data</a>, <a id='1437' tid='1438', class="m">&#39; &#39;</a>);
}


// Reads a file into a v8 string.
<a id='1323' tid='1324', class="m">Handle</a>&lt;<a id='1325' tid='1326', class="m">String</a>&gt; <a id='1327' tid='1328', class="m">Shell</a><a id='1329' tid='1330', class="m">::</a><a id='1331' tid='1332', class="m">ReadFile</a>(<a id='1333' tid='1334', class="m">const</a> <a id='1335' tid='1336', class="m">char</a><a id='1337' tid='1338', class="m">*</a> <a id='1339' tid='1340', class="m">name</a>) {
  <a id='1341' tid='1342', class="m">int</a> <a id='1343' tid='1344', class="m">size</a> = <a id='1345' tid='1346', class="m">0</a>;
  <a id='1347' tid='1348', class="m">char</a><a id='1349' tid='1350', class="m">*</a> <a id='1351' tid='1352', class="m">chars</a> = <a id='1353' tid='1354', class="m">ReadChars</a>(<a id='1355' tid='1356', class="m">name</a>, <a id='1357' tid='1358', class="m">&</a><a id='1359' tid='1360', class="m">size</a>);
  <a id='1361' tid='1362', class="m">if</a> (<a id='1363' tid='1364', class="m">chars</a> <a id='1365' tid='1366', class="m">==</a> <a id='1367' tid='1368', class="m">NULL</a>) <a id='1369' tid='1370', class="m">return</a> <a id='1371' tid='1372', class="m">Handle</a>&lt;<a id='1373' tid='1374', class="m">String</a>&gt;();
  <a id='1375' tid='1376', class="m">Handle</a>&lt;<a id='1377' tid='1378', class="m">String</a>&gt; <a id='1379' tid='1380', class="m">result</a> = <a id='1381' tid='1382', class="m">String</a><a id='1383' tid='1384', class="m">::</a><a id='1385' tid='1386', class="m">New</a>(<a id='1387' tid='1388', class="m">chars</a>);
  <a id='1389' tid='1390', class="m">delete</a>[] <a id='1391' tid='1392', class="m">chars</a>;
  <a id='1393' tid='1394', class="m">return</a> <a id='1395' tid='1396', class="m">result</a>;
}


<a id='1283' tid='1284', class="m">void</a> <a id='1285' tid='1286', class="m">Shell</a><a id='1287' tid='1288', class="m">::</a><a id='1289' tid='1290', class="m">RunShell</a>() {
  <a id='1291' tid='1292', class="m">LineEditor</a><a id='1293' tid='1294', class="m">*</a> <a id='1295' tid='1296', class="m">editor</a> = <a id='1297' tid='1298', class="m">LineEditor</a><a id='1299' tid='1300', class="m">::</a><a id='1301' tid='1302', class="m">Get</a>();
  <a id='1269' tid='1270', class="m">printf</a>(<a id='1271' tid='1272', class="m">&quot;V8 version %s [console: %s]\n&quot;</a>, <a id='1273' tid='1274', class="m">V8</a><a id='1275' tid='1276', class="m">::</a><a id='1277' tid='1278', class="m">GetVersion</a>(), <a id='1279' tid='1280', class="m">editor</a>-&gt;<a id='1281' tid='1282', class="m">name</a>());
  <span class="d">editor-&gt;Open();</span>
  <a id='1105' tid='1106', class="m">while</a> (<a id='1107' tid='1108', class="m">true</a>) {
    <a id='1119' tid='1120', class="m">Locker</a> <a id='1121' tid='1122', class="m">locker</a>;
    <a id='1123' tid='1124', class="m">HandleScope</a> <a id='1125' tid='1126', class="m">handle_scope</a>;
    <a id='1109' tid='1110', class="m">Context</a><a id='1111' tid='1112', class="m">::</a><a id='1113' tid='1114', class="m">Scope</a> <a id='1115' tid='1116', class="m">context_scope</a>(<a id='1117' tid='1118', class="m">evaluation_context_</a>);
    <a id='1127' tid='1128', class="m">i</a><a id='1129' tid='1130', class="m">::</a><a id='1131' tid='1132', class="m">SmartPointer</a>&lt;<a id='1133' tid='1134', class="m">char</a>&gt; <a id='1135' tid='1136', class="m">input</a> = <a id='1137' tid='1138', class="m">editor</a>-&gt;<a id='1139' tid='1140', class="m">Prompt</a>(<a id='1141' tid='1142', class="m">Shell</a><a id='1143' tid='1144', class="m">::</a><a id='1145' tid='1146', class="m">kPrompt</a>);
    <a id='1147' tid='1148', class="m">if</a> (<a id='1149' tid='1150', class="m">input</a>.<a id='1151' tid='1152', class="m">is_empty</a>())
      <a id='1153' tid='1154', class="m">break</a>;
    <a id='1155' tid='1156', class="m">editor</a>-&gt;<a id='1157' tid='1158', class="m">AddHistory</a>(<a id='1159' tid='1160', class="m">*</a><a id='1161' tid='1162', class="m">input</a>);
    <a id='1163' tid='1164', class="m">Handle</a>&lt;<a id='1165' tid='1166', class="m">String</a>&gt; <a id='1167' tid='1168', class="m">name</a> = <a id='1169' tid='1170', class="m">String</a><a id='1171' tid='1172', class="m">::</a><a id='1173' tid='1174', class="m">New</a>(<a id='1175' tid='1176', class="m">&quot;(d8)&quot;</a>);
    <a id='1177' tid='1178', class="m">ExecuteString</a>(<a id='1179' tid='1180', class="m">String</a><a id='1181' tid='1182', class="m">::</a><a id='1183' tid='1184', class="m">New</a>(<a id='1185' tid='1186', class="m">*</a><a id='1187' tid='1188', class="m">input</a>), <a id='1189' tid='1190', class="m">name</a>, <a id='1191' tid='1192', class="m">true</a>, <a id='1193' tid='1194', class="m">true</a>);
  }
  <span class="d">editor-&gt;Close();</span>
  <span class="d">printf(&quot;\n&quot;);</span>
}


<a id='1195' tid='1196', class="m">class</a> <a id='1197' tid='1198', class="m">ShellThread</a> : <a id='1199' tid='1200', class="m">public</a> <a id='1201' tid='1202', class="m">i</a><a id='1203' tid='1204', class="m">::</a><a id='1205' tid='1206', class="m">Thread</a> {
 <a id='1229' tid='1230', class="m">public</a>:
  <a id='1065' tid='1066', class="m">ShellThread</a>(<a id='1213' tid='1214', class="m">int</a> <a id='1215' tid='1216', class="m">no</a>, <a id='1217' tid='1218', class="m">i</a><a id='1219' tid='1220', class="m">::</a><a id='1221' tid='1222', class="m">Vector</a>&lt;<a id='1223' tid='1224', class="m">const</a> <a id='1225' tid='1226', class="m">char</a>&gt; <a id='1227' tid='1228', class="m">files</a>)
    : <span class="d">no_(no), files_(files)</span> <span class="d">{ }</span>
  <a id='1207' tid='1208', class="m">virtual</a> <a id='1209' tid='1210', class="m">void</a> <a id='1211' tid='1212', class="m">Run</a>();
 <a id='1231' tid='1232', class="m">private</a>:
  <a id='1233' tid='1234', class="m">int</a> <a id='1235' tid='1236', class="m">no_</a>;
  <a id='1237' tid='1238', class="m">i</a><a id='1239' tid='1240', class="m">::</a><a id='1241' tid='1242', class="m">Vector</a>&lt;<a id='1243' tid='1244', class="m">const</a> <a id='1245' tid='1246', class="m">char</a>&gt; <a id='1247' tid='1248', class="m">files_</a>;
};


<span class="d">void</span> <span class="d">ShellThread::Run</span><span class="d">()</span> {
  // Prepare the context for this thread.
  <span class="d">Locker locker;</span>
  <span class="d">HandleScope scope;</span>
  <a id='1923' tid='1924', class="m">Handle</a>&lt;<a id='1925' tid='1926', class="m">ObjectTemplate</a>&gt; <a id='1927' tid='1928', class="m">global_template</a> = <a id='1929' tid='1930', class="m">ObjectTemplate</a><a id='1931' tid='1932', class="m">::</a><a id='1933' tid='1934', class="m">New</a>();
  <span class="d">global_template-&gt;Set(String::New(&quot;print&quot;),
                       FunctionTemplate::New(Shell::Print));</span>
  <span class="d">global_template-&gt;Set(String::New(&quot;write&quot;),
                       FunctionTemplate::New(Shell::Write));</span>
  <span class="d">global_template-&gt;Set(String::New(&quot;read&quot;),
                       FunctionTemplate::New(Shell::Read));</span>
  <span class="d">global_template-&gt;Set(String::New(&quot;readline&quot;),
                       FunctionTemplate::New(Shell::ReadLine));</span>
  <span class="d">global_template-&gt;Set(String::New(&quot;load&quot;),
                       FunctionTemplate::New(Shell::Load));</span>
  <span class="d">global_template-&gt;Set(String::New(&quot;yield&quot;),
                       FunctionTemplate::New(Shell::Yield));</span>
  <span class="d">global_template-&gt;Set(String::New(&quot;version&quot;),
                       FunctionTemplate::New(Shell::Version));</span>

  <a id='457' tid='458', class="m">char</a><a id='459' tid='460', class="m">*</a> <a id='461' tid='462', class="m">ptr</a> = <a id='463' tid='464', class="m">const_cast</a>&lt;<a id='465' tid='466', class="m">char</a><a id='467' tid='468', class="m">*</a>&gt;(<a id='469' tid='470', class="m">files_</a>.<a id='471' tid='472', class="m">start</a>());
  <a id='473' tid='474', class="m">while</a> ((<a id='575' tid='576', class="m">ptr</a> <a id='577' tid='578', class="m">!=</a> <a id='579' tid='580', class="m">NULL</a>) <a id='581' tid='582', class="m">&&</a> (<a id='583' tid='584', class="m">*</a><a id='585' tid='586', class="m">ptr</a> <a id='587' tid='588', class="m">!=</a> <a id='589' tid='590', class="m">&#39;\0&#39;</a>)) {
    // For each newline-separated line.
    <a id='329' tid='330', class="m">char</a><a id='331' tid='332', class="m">*</a> <a id='333' tid='334', class="m">next_line</a> = <a id='335' tid='336', class="m">ReadLine</a>(<a id='337' tid='338', class="m">ptr</a>);

    <a id='295' tid='296', class="m">if</a> (<a id='297' tid='298', class="m">*</a><a id='299' tid='300', class="m">ptr</a> <a id='301' tid='302', class="m">==</a> <a id='303' tid='304', class="m">&#39;#&#39;</a>) {
      // Skip comment lines.
      <a id='305' tid='306', class="m">ptr</a> <a id='307' tid='308', class="m">=</a> <a id='309' tid='310', class="m">next_line</a>;
      <a id='311' tid='312', class="m">continue</a>;
    }

    <span class="d">Persistent&lt;Context&gt; thread_context = Context::New(NULL, global_template);</span>
    <span class="d">thread_context-&gt;SetSecurityToken(Undefined());</span>
    <a id='275' tid='276', class="m">Context</a><a id='277' tid='278', class="m">::</a><a id='279' tid='280', class="m">Scope</a> <a id='281' tid='282', class="m">context_scope</a>(<a id='283' tid='284', class="m">thread_context</a>);

    <a id='339' tid='340', class="m">while</a> ((<a id='475' tid='476', class="m">ptr</a> <a id='477' tid='478', class="m">!=</a> <a id='479' tid='480', class="m">NULL</a>) <a id='481' tid='482', class="m">&&</a> (<a id='483' tid='484', class="m">*</a><a id='485' tid='486', class="m">ptr</a> <a id='487' tid='488', class="m">!=</a> <a id='489' tid='490', class="m">&#39;\0&#39;</a>)) {
      <a id='341' tid='342', class="m">char</a><a id='343' tid='344', class="m">*</a> <a id='345' tid='346', class="m">filename</a> = <a id='347' tid='348', class="m">ptr</a>;
      <a id='349' tid='350', class="m">ptr</a> <a id='351' tid='352', class="m">=</a> <a id='353' tid='354', class="m">ReadWord</a>(<a id='355' tid='356', class="m">ptr</a>);

      // Skip empty strings.
      <a id='357' tid='358', class="m">if</a> (<a id='359' tid='360', class="m">strlen</a>(<a id='361' tid='362', class="m">filename</a>) <a id='363' tid='364', class="m">==</a> <a id='365' tid='366', class="m">0</a>) {
        <a id='367' tid='368', class="m">break</a>;
      }

      <a id='369' tid='370', class="m">Handle</a>&lt;<a id='371' tid='372', class="m">String</a>&gt; <a id='373' tid='374', class="m">str</a> = <a id='375' tid='376', class="m">Shell</a><a id='377' tid='378', class="m">::</a><a id='379' tid='380', class="m">ReadFile</a>(<a id='381' tid='382', class="m">filename</a>);
      <a id='383' tid='384', class="m">if</a> (<a id='385' tid='386', class="m">str</a>.<a id='387' tid='388', class="m">IsEmpty</a>()) {
        <a id='389' tid='390', class="m">printf</a>(<a id='391' tid='392', class="m">&quot;WARNING: %s not found\n&quot;</a>, <a id='393' tid='394', class="m">filename</a>);
        <a id='395' tid='396', class="m">break</a>;
      }

      <a id='397' tid='398', class="m">Shell</a><a id='399' tid='400', class="m">::</a><a id='401' tid='402', class="m">ExecuteString</a>(<a id='403' tid='404', class="m">str</a>, <a id='405' tid='406', class="m">String</a><a id='407' tid='408', class="m">::</a><a id='409' tid='410', class="m">New</a>(<a id='411' tid='412', class="m">filename</a>), <a id='413' tid='414', class="m">false</a>, <a id='415' tid='416', class="m">false</a>);
    }

    <span class="d">thread_context.Dispose();</span>
    <span class="d">ptr = next_line;</span>
  }
}


<span class="d">int</span> <span class="d">Shell::Main</span><span class="d">(int argc, char* argv[])</span> {
  <span class="d">i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);</span>
  <span class="d">if (i::FLAG_help) {
    return 1;
  }</span>
  <span class="d">Initialize();</span>
  <span class="d">bool run_shell = (argc == 1);</span>

  // Default use preemption if threads are created.
  <span class="d">bool use_preemption = true;</span>

  // Default to use lowest possible thread preemption interval to test as many
  // edgecases as possible.
  <span class="d">int preemption_interval = 1;</span>

  <a id='1067' tid='1068', class="m">i</a><a id='1069' tid='1070', class="m">::</a><a id='1071' tid='1072', class="m">List</a>&lt;<a id='1073' tid='1074', class="m">i</a><a id='1075' tid='1076', class="m">::</a><a id='1077' tid='1078', class="m">Thread</a><a id='1079' tid='1080', class="m">*</a>&gt; <a id='1081' tid='1082', class="m">threads</a>(<a id='1083' tid='1084', class="m">1</a>);

  {
    // Acquire the V8 lock once initialization has finished. Since the thread
    // below may spawn new threads accessing V8 holding the V8 lock here is
    // mandatory.
    <span class="d">Locker locker;</span>
    <a id='1055' tid='1056', class="m">Context</a><a id='1057' tid='1058', class="m">::</a><a id='1059' tid='1060', class="m">Scope</a> <a id='1061' tid='1062', class="m">context_scope</a>(<a id='1063' tid='1064', class="m">evaluation_context_</a>);
    <a id='1005' tid='1006', class="m">for</a> (<a id='1007' tid='1008', class="m">int</a> <a id='1009' tid='1010', class="m">i</a> = <a id='1011' tid='1012', class="m">1</a>; <a id='1013' tid='1014', class="m">i</a> <a id='1015' tid='1016', class="m">&lt;</a> <a id='1017' tid='1018', class="m">argc</a>; <a id='1019' tid='1020', class="m">i</a><a id='1021' tid='1022', class="m">++</a>) {
      <a id='1023' tid='1024', class="m">char</a><a id='1025' tid='1026', class="m">*</a> <a id='1027' tid='1028', class="m">str</a> = <a id='1029' tid='1030', class="m">argv</a>[<a id='1031' tid='1032', class="m">i</a>];
      <span class="d">if</span> <span class="d">(strcmp(str, &quot;--shell&quot;) == 0)</span> <span class="d">{
        run_shell = true;
      }</span> <span class="d">else</span> <a id='669' tid='670', class="m">if</a> (<a id='1033' tid='1034', class="m">strcmp</a>(<a id='1035' tid='1036', class="m">str</a>, <a id='1037' tid='1038', class="m">&quot;--preemption&quot;</a>) <a id='1039' tid='1040', class="m">==</a> <a id='1041' tid='1042', class="m">0</a>) {
        <a id='671' tid='672', class="m">use_preemption</a> <a id='673' tid='674', class="m">=</a> <a id='675' tid='676', class="m">true</a>;
      } <a id='677' tid='678', class="m">else</a> <a id='679' tid='680', class="m">if</a> (<a id='681' tid='682', class="m">strcmp</a>(<a id='683' tid='684', class="m">str</a>, <a id='685' tid='686', class="m">&quot;--no-preemption&quot;</a>) <a id='687' tid='688', class="m">==</a> <a id='689' tid='690', class="m">0</a>) {
        <a id='691' tid='692', class="m">use_preemption</a> <a id='693' tid='694', class="m">=</a> <a id='695' tid='696', class="m">false</a>;
      } <a id='697' tid='698', class="m">else</a> <a id='699' tid='700', class="m">if</a> (<a id='701' tid='702', class="m">strcmp</a>(<a id='703' tid='704', class="m">str</a>, <a id='705' tid='706', class="m">&quot;--preemption-interval&quot;</a>) <a id='707' tid='708', class="m">==</a> <a id='709' tid='710', class="m">0</a>) {
        <a id='711' tid='712', class="m">if</a> (<a id='713' tid='714', class="m">i</a> <a id='715' tid='716', class="m">+</a> <a id='717' tid='718', class="m">1</a> <a id='719' tid='720', class="m">&lt;</a> <a id='721' tid='722', class="m">argc</a>) {
          <a id='723' tid='724', class="m">char</a><a id='725' tid='726', class="m">*</a> <a id='727' tid='728', class="m">end</a> = <a id='729' tid='730', class="m">NULL</a>;
          <a id='731' tid='732', class="m">preemption_interval</a> <a id='733' tid='734', class="m">=</a> <a id='735' tid='736', class="m">strtol</a>(<a id='737' tid='738', class="m">argv</a>[<a id='739' tid='740', class="m">++</a><a id='741' tid='742', class="m">i</a>], <a id='743' tid='744', class="m">&</a><a id='745' tid='746', class="m">end</a>, <a id='747' tid='748', class="m">10</a>);  // NOLINT
          <a id='749' tid='750', class="m">if</a> (<a id='751' tid='752', class="m">preemption_interval</a> <a id='753' tid='754', class="m">&lt;=</a> <a id='755' tid='756', class="m">0</a> <a id='757' tid='758', class="m">||</a> <a id='759' tid='760', class="m">*</a><a id='761' tid='762', class="m">end</a> <a id='763' tid='764', class="m">!=</a> <a id='765' tid='766', class="m">&#39;\0&#39;</a> <a id='767' tid='768', class="m">||</a> <a id='769' tid='770', class="m">errno</a> <a id='771' tid='772', class="m">==</a> <a id='773' tid='774', class="m">ERANGE</a>) {
            <a id='775' tid='776', class="m">printf</a>(<a id='777' tid='778', class="m">&quot;Invalid value for --preemption-interval &#39;%s&#39;\n&quot;</a>, <a id='779' tid='780', class="m">argv</a>[<a id='781' tid='782', class="m">i</a>]);
            <a id='783' tid='784', class="m">return</a> <a id='785' tid='786', class="m">1</a>;
          }
        } <a id='787' tid='788', class="m">else</a> {
          <a id='789' tid='790', class="m">printf</a>(<a id='791' tid='792', class="m">&quot;Missing value for --preemption-interval\n&quot;</a>);
          <a id='793' tid='794', class="m">return</a> <a id='795' tid='796', class="m">1</a>;
       }
      } <a id='797' tid='798', class="m">else</a> <a id='799' tid='800', class="m">if</a> (<a id='801' tid='802', class="m">strcmp</a>(<a id='803' tid='804', class="m">str</a>, <a id='805' tid='806', class="m">&quot;-f&quot;</a>) <a id='807' tid='808', class="m">==</a> <a id='809' tid='810', class="m">0</a>) {
        // Ignore any -f flags for compatibility with other stand-alone
        // JavaScript engines.
        <a id='811' tid='812', class="m">continue</a>;
      } <a id='813' tid='814', class="m">else</a> <a id='815' tid='816', class="m">if</a> (<a id='817' tid='818', class="m">strncmp</a>(<a id='819' tid='820', class="m">str</a>, <a id='821' tid='822', class="m">&quot;--&quot;</a>, <a id='823' tid='824', class="m">2</a>) <a id='825' tid='826', class="m">==</a> <a id='827' tid='828', class="m">0</a>) {
        <a id='829' tid='830', class="m">printf</a>(<a id='831' tid='832', class="m">&quot;Warning: unknown flag %s.\nTry --help for options\n&quot;</a>, <a id='833' tid='834', class="m">str</a>);
      } <a id='835' tid='836', class="m">else</a> <a id='837' tid='838', class="m">if</a> (<a id='839' tid='840', class="m">strcmp</a>(<a id='841' tid='842', class="m">str</a>, <a id='843' tid='844', class="m">&quot;-e&quot;</a>) <a id='845' tid='846', class="m">==</a> <a id='847' tid='848', class="m">0</a> <a id='849' tid='850', class="m">&&</a> <a id='851' tid='852', class="m">i</a> <a id='853' tid='854', class="m">+</a> <a id='855' tid='856', class="m">1</a> <a id='857' tid='858', class="m">&lt;</a> <a id='859' tid='860', class="m">argc</a>) {
        // Execute argument given to -e option directly.
        <span class="d">v8::HandleScope handle_scope;</span>
        <a id='861' tid='862', class="m">v8</a><a id='863' tid='864', class="m">::</a><a id='865' tid='866', class="m">Handle</a>&lt;<a id='867' tid='868', class="m">v8</a><a id='869' tid='870', class="m">::</a><a id='871' tid='872', class="m">String</a>&gt; <a id='873' tid='874', class="m">file_name</a> = <a id='875' tid='876', class="m">v8</a><a id='877' tid='878', class="m">::</a><a id='879' tid='880', class="m">String</a><a id='881' tid='882', class="m">::</a><a id='883' tid='884', class="m">New</a>(<a id='885' tid='886', class="m">&quot;unnamed&quot;</a>);
        <a id='591' tid='592', class="m">v8</a><a id='593' tid='594', class="m">::</a><a id='595' tid='596', class="m">Handle</a>&lt;<a id='597' tid='598', class="m">v8</a><a id='599' tid='600', class="m">::</a><a id='601' tid='602', class="m">String</a>&gt; <a id='603' tid='604', class="m">source</a> = <a id='605' tid='606', class="m">v8</a><a id='607' tid='608', class="m">::</a><a id='609' tid='610', class="m">String</a><a id='611' tid='612', class="m">::</a><a id='613' tid='614', class="m">New</a><span class="d">(argv[i + 1])</span>;
        <a id='491' tid='492', class="m">if</a> (<a id='493' tid='494', class="m">!</a><a id='495' tid='496', class="m">ExecuteString</a>(<a id='497' tid='498', class="m">source</a>, <a id='499' tid='500', class="m">file_name</a>, <a id='501' tid='502', class="m">false</a>, <a id='503' tid='504', class="m">true</a>)) {
          <a id='505' tid='506', class="m">OnExit</a>();
          <a id='507' tid='508', class="m">return</a> <a id='509' tid='510', class="m">1</a>;
        }
        <span class="d">i++;</span>
      } <a id='887' tid='888', class="m">else</a> <a id='889' tid='890', class="m">if</a> (<a id='891' tid='892', class="m">strcmp</a>(<a id='893' tid='894', class="m">str</a>, <a id='895' tid='896', class="m">&quot;-p&quot;</a>) <a id='897' tid='898', class="m">==</a> <a id='899' tid='900', class="m">0</a> <a id='901' tid='902', class="m">&&</a> <a id='903' tid='904', class="m">i</a> <a id='905' tid='906', class="m">+</a> <a id='907' tid='908', class="m">1</a> <a id='909' tid='910', class="m">&lt;</a> <a id='911' tid='912', class="m">argc</a>) {
        <span class="d">int size = 0;</span>
        <a id='913' tid='914', class="m">const</a> <a id='915' tid='916', class="m">char</a><a id='917' tid='918', class="m">*</a> <a id='919' tid='920', class="m">files</a> = <a id='921' tid='922', class="m">ReadChars</a>(<a id='923' tid='924', class="m">argv</a>[<a id='925' tid='926', class="m">++</a><a id='927' tid='928', class="m">i</a>], <a id='929' tid='930', class="m">&</a><a id='931' tid='932', class="m">size</a>);
        <a id='615' tid='616', class="m">if</a> (<a id='617' tid='618', class="m">files</a> <a id='619' tid='620', class="m">==</a> <a id='621' tid='622', class="m">NULL</a>) <a id='623' tid='624', class="m">return</a> <a id='625' tid='626', class="m">1</a>;
        <a id='511' tid='512', class="m">ShellThread</a><a id='513' tid='514', class="m">*</a> <a id='515' tid='516', class="m">thread</a> =
            <a id='517' tid='518', class="m">new</a> <a id='519' tid='520', class="m">ShellThread</a>(<a id='521' tid='522', class="m">threads</a>.<a id='523' tid='524', class="m">length</a>(),
                            <a id='525' tid='526', class="m">i</a><a id='527' tid='528', class="m">::</a><a id='529' tid='530', class="m">Vector</a>&lt;<a id='531' tid='532', class="m">const</a> <a id='533' tid='534', class="m">char</a>&gt;(<a id='535' tid='536', class="m">files</a>, <a id='537' tid='538', class="m">size</a>));
        <span class="d">thread-&gt;Start();</span>
        <span class="d">threads.Add(thread);</span>
      } <a id='933' tid='934', class="m">else</a> {
        // Use all other arguments as names of files to load and run.
        <span class="d">HandleScope handle_scope;</span>
        <a id='935' tid='936', class="m">Handle</a>&lt;<a id='937' tid='938', class="m">String</a>&gt; <a id='939' tid='940', class="m">file_name</a> = <a id='941' tid='942', class="m">v8</a><a id='943' tid='944', class="m">::</a><a id='945' tid='946', class="m">String</a><a id='947' tid='948', class="m">::</a><a id='949' tid='950', class="m">New</a>(<a id='951' tid='952', class="m">str</a>);
        <a id='627' tid='628', class="m">Handle</a>&lt;<a id='629' tid='630', class="m">String</a>&gt; <a id='631' tid='632', class="m">source</a> = <a id='633' tid='634', class="m">ReadFile</a>(<a id='635' tid='636', class="m">str</a>);
        <a id='539' tid='540', class="m">if</a> (<a id='541' tid='542', class="m">source</a>.<a id='543' tid='544', class="m">IsEmpty</a>()) {
          <a id='545' tid='546', class="m">printf</a>(<a id='547' tid='548', class="m">&quot;Error reading &#39;%s&#39;\n&quot;</a>, <a id='549' tid='550', class="m">str</a>);
          <a id='551' tid='552', class="m">return</a> <a id='553' tid='554', class="m">1</a>;
        }
        <a id='417' tid='418', class="m">if</a> (<a id='419' tid='420', class="m">!</a><a id='421' tid='422', class="m">ExecuteString</a>(<a id='423' tid='424', class="m">source</a>, <a id='425' tid='426', class="m">file_name</a>, <a id='427' tid='428', class="m">false</a>, <a id='429' tid='430', class="m">true</a>)) {
          <a id='431' tid='432', class="m">OnExit</a>();
          <a id='433' tid='434', class="m">return</a> <a id='435' tid='436', class="m">1</a>;
        }
      }
    }

    // Start preemption if threads have been created and preemption is enabled.
    <a id='647' tid='648', class="m">if</a> (<a id='649' tid='650', class="m">threads</a>.<a id='651' tid='652', class="m">length</a>() <a id='653' tid='654', class="m">&gt;</a> <a id='655' tid='656', class="m">0</a> <a id='657' tid='658', class="m">&&</a> <a id='659' tid='660', class="m">use_preemption</a>) {
      <a id='661' tid='662', class="m">Locker</a><a id='663' tid='664', class="m">::</a><a id='665' tid='666', class="m">StartPreemption</a>(<a id='667' tid='668', class="m">preemption_interval</a>);
    }

<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
    // Run the remote debugger if requested.
    <span class="d">if (i::FLAG_remote_debugger) {
      RunRemoteDebugger(i::FLAG_debugger_port);
      return 0;
    }</span>
<span class="d">#endif</span>
  }
  <span class="d">if (run_shell)
    RunShell();</span>
  <a id='963' tid='964', class="m">for</a> (<a id='965' tid='966', class="m">int</a> <a id='967' tid='968', class="m">i</a> = <a id='969' tid='970', class="m">0</a>; <a id='971' tid='972', class="m">i</a> <a id='973' tid='974', class="m">&lt;</a> <a id='975' tid='976', class="m">threads</a>.<a id='977' tid='978', class="m">length</a>(); <a id='979' tid='980', class="m">i</a><a id='981' tid='982', class="m">++</a>) {
    <a id='983' tid='984', class="m">i</a><a id='985' tid='986', class="m">::</a><a id='987' tid='988', class="m">Thread</a><a id='989' tid='990', class="m">*</a> <a id='991' tid='992', class="m">thread</a> = <a id='993' tid='994', class="m">threads</a>[<a id='995' tid='996', class="m">i</a>];
    <a id='997' tid='998', class="m">thread</a>-&gt;<a id='999' tid='1000', class="m">Join</a>();
    <a id='1001' tid='1002', class="m">delete</a> <a id='1003' tid='1004', class="m">thread</a>;
  }
  <span class="d">OnExit();</span>
  <span class="d">return 0;</span>
}


}  // namespace v8


<a id='4217' tid='4218', class="m">int</a> <a id='4219' tid='4220', class="m">main</a>(<a id='4221' tid='4222', class="m">int</a> <a id='4223' tid='4224', class="m">argc</a>, <a id='4225' tid='4226', class="m">char</a><a id='4227' tid='4228', class="m">*</a> <a id='4229' tid='4230', class="m">argv</a>[]) {
  <a id='4231' tid='4232', class="m">return</a> <a id='4233' tid='4234', class="m">v8</a><a id='4235' tid='4236', class="m">::</a><a id='4237' tid='4238', class="m">Shell</a><a id='4239' tid='4240', class="m">::</a><a id='4241' tid='4242', class="m">Main</a>(<a id='4243' tid='4244', class="m">argc</a>, <a id='4245' tid='4246', class="m">argv</a>);
}

</pre>
</div>
<div id="right" class="src">
<pre>
<a id='rightstart' tid='leftstart'></a>
// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


<span class="i">#ifdef COMPRESS_STARTUP_DATA_BZ2</span>
<span class="i">#include &lt;bzlib.h&gt;</span>
<span class="i">#endif</span>
#<a id='4288' tid='4287', class="m">include</a> <a id='4290' tid='4289', class="m">&lt;</a><a id='4292' tid='4291', class="m">errno</a><a id='4294' tid='4293', class="m">.</a><a id='4296' tid='4295', class="m">h</a><a id='4298' tid='4297', class="m">&gt;</a>
#<a id='4276' tid='4275', class="m">include</a> <a id='4278' tid='4277', class="m">&lt;</a><a id='4280' tid='4279', class="m">stdlib</a><a id='4282' tid='4281', class="m">.</a><a id='4284' tid='4283', class="m">h</a><a id='4286' tid='4285', class="m">&gt;</a>

<span class="i">#include &quot;v8.h&quot;</span>

<span class="i">#include &quot;d8.h&quot;</span>
<span class="i">#include &quot;d8-debug.h&quot;</span>
<span class="i">#include &quot;debug.h&quot;</span>
<span class="i">#include &quot;api.h&quot;</span>
<span class="i">#include &quot;natives.h&quot;</span>
<span class="i">#include &quot;platform.h&quot;</span>


namespace <span class="i">v8</span> {


<a id='4262' tid='4261', class="m">const</a> <a id='4264' tid='4263', class="m">char</a><a id='4266' tid='4265', class="m">*</a> <a id='4268' tid='4267', class="m">Shell</a><a id='4270' tid='4269', class="m">::</a><a id='4272' tid='4271', class="m">kHistoryFileName</a> = <a id='4274' tid='4273', class="m">&quot;.d8_history&quot;</a>;
<a id='4248' tid='4247', class="m">const</a> <a id='4250' tid='4249', class="m">char</a><a id='4252' tid='4251', class="m">*</a> <a id='4254' tid='4253', class="m">Shell</a><a id='4256' tid='4255', class="m">::</a><a id='4258' tid='4257', class="m">kPrompt</a> = <a id='4260' tid='4259', class="m">&quot;d8&gt; &quot;</a>;


<a id='4206' tid='4205', class="m">LineEditor</a> <a id='4208' tid='4207', class="m">*</a><a id='4210' tid='4209', class="m">LineEditor</a><a id='4212' tid='4211', class="m">::</a><a id='4214' tid='4213', class="m">first_</a> = <a id='4216' tid='4215', class="m">NULL</a>;


<a id='4170' tid='4169', class="m">LineEditor</a><a id='4172' tid='4171', class="m">::</a><a id='4174' tid='4173', class="m">LineEditor</a>(<a id='4176' tid='4175', class="m">Type</a> <a id='4178' tid='4177', class="m">type</a>, <a id='4180' tid='4179', class="m">const</a> <a id='4182' tid='4181', class="m">char</a><a id='4184' tid='4183', class="m">*</a> <a id='4186' tid='4185', class="m">name</a>)
    : <a id='4188' tid='4187', class="m">type_</a>(<a id='4190' tid='4189', class="m">type</a>),
      <a id='4192' tid='4191', class="m">name_</a>(<a id='4194' tid='4193', class="m">name</a>),
      <a id='4196' tid='4195', class="m">next_</a>(<a id='4198' tid='4197', class="m">first_</a>) {
  <a id='4200' tid='4199', class="m">first_</a> <a id='4202' tid='4201', class="m">=</a> <a id='4204' tid='4203', class="m">this</a>;
}


<a id='4106' tid='4105', class="m">LineEditor</a><a id='4108' tid='4107', class="m">*</a> <a id='4110' tid='4109', class="m">LineEditor</a><a id='4112' tid='4111', class="m">::</a><a id='4114' tid='4113', class="m">Get</a>() {
  <a id='4116' tid='4115', class="m">LineEditor</a><a id='4118' tid='4117', class="m">*</a> <a id='4120' tid='4119', class="m">current</a> = <a id='4122' tid='4121', class="m">first_</a>;
  <a id='4124' tid='4123', class="m">LineEditor</a><a id='4126' tid='4125', class="m">*</a> <a id='4128' tid='4127', class="m">best</a> = <a id='4130' tid='4129', class="m">current</a>;
  <a id='4132' tid='4131', class="m">while</a> (<a id='4134' tid='4133', class="m">current</a> <a id='4136' tid='4135', class="m">!=</a> <a id='4138' tid='4137', class="m">NULL</a>) {
    <a id='4140' tid='4139', class="m">if</a> (<a id='4142' tid='4141', class="m">current</a>-&gt;<a id='4144' tid='4143', class="m">type_</a> <a id='4146' tid='4145', class="m">&gt;</a> <a id='4148' tid='4147', class="m">best</a>-&gt;<a id='4150' tid='4149', class="m">type_</a>)
      <a id='4152' tid='4151', class="m">best</a> <a id='4154' tid='4153', class="m">=</a> <a id='4156' tid='4155', class="m">current</a>;
    <a id='4158' tid='4157', class="m">current</a> <a id='4160' tid='4159', class="m">=</a> <a id='4162' tid='4161', class="m">current</a>-&gt;<a id='4164' tid='4163', class="m">next_</a>;
  }
  <a id='4166' tid='4165', class="m">return</a> <a id='4168' tid='4167', class="m">best</a>;
}


<a id='4064' tid='4063', class="m">class</a> <a id='4066' tid='4065', class="m">DumbLineEditor</a>: <a id='4068' tid='4067', class="m">public</a> <a id='4070' tid='4069', class="m">LineEditor</a> {
  <a id='4104' tid='4103', class="m">public</a>:
    <a id='4072' tid='4071', class="m">DumbLineEditor</a>() : <a id='4074' tid='4073', class="m">LineEditor</a>(<a id='4076' tid='4075', class="m">LineEditor</a><a id='4078' tid='4077', class="m">::</a><a id='4080' tid='4079', class="m">DUMB</a>, <a id='4082' tid='4081', class="m">&quot;dumb&quot;</a>) { }
   <a id='4084' tid='4083', class="m">virtual</a> <a id='4086' tid='4085', class="m">i</a><a id='4088' tid='4087', class="m">::</a><a id='4090' tid='4089', class="m">SmartPointer</a>&lt;<a id='4092' tid='4091', class="m">char</a>&gt; <a id='4094' tid='4093', class="m">Prompt</a>(<a id='4096' tid='4095', class="m">const</a> <a id='4098' tid='4097', class="m">char</a><a id='4100' tid='4099', class="m">*</a> <a id='4102' tid='4101', class="m">prompt</a>);
};


  <span class="i">static DumbLineEditor dumb_line_editor;</span>


<a id='3984' tid='3983', class="m">i</a><a id='3986' tid='3985', class="m">::</a><a id='3988' tid='3987', class="m">SmartPointer</a>&lt;<a id='3990' tid='3989', class="m">char</a>&gt; <a id='3992' tid='3991', class="m">DumbLineEditor</a><a id='3994' tid='3993', class="m">::</a><a id='3996' tid='3995', class="m">Prompt</a>(<a id='3998' tid='3997', class="m">const</a> <a id='4000' tid='3999', class="m">char</a><a id='4002' tid='4001', class="m">*</a> <a id='4004' tid='4003', class="m">prompt</a>) {
  <a id='4006' tid='4005', class="m">static</a> <a id='4008' tid='4007', class="m">const</a> <a id='4010' tid='4009', class="m">int</a> <a id='4012' tid='4011', class="m">kBufferSize</a> = <a id='4014' tid='4013', class="m">256</a>;
  <a id='4016' tid='4015', class="m">char</a> <a id='4018' tid='4017', class="m">buffer</a>[<a id='4020' tid='4019', class="m">kBufferSize</a>];
  <a id='4022' tid='4021', class="m">printf</a>(<a id='4024' tid='4023', class="m">&quot;%s&quot;</a>, <a id='4026' tid='4025', class="m">prompt</a>);
  <a id='4028' tid='4027', class="m">char</a><a id='4030' tid='4029', class="m">*</a> <a id='4032' tid='4031', class="m">str</a> = <a id='4034' tid='4033', class="m">fgets</a>(<a id='4036' tid='4035', class="m">buffer</a>, <a id='4038' tid='4037', class="m">kBufferSize</a>, <a id='4040' tid='4039', class="m">stdin</a>);
  <a id='4042' tid='4041', class="m">return</a> <a id='4044' tid='4043', class="m">i</a><a id='4046' tid='4045', class="m">::</a><a id='4048' tid='4047', class="m">SmartPointer</a>&lt;<a id='4050' tid='4049', class="m">char</a>&gt;(<a id='4052' tid='4051', class="m">str</a> ? <a id='4054' tid='4053', class="m">i</a><a id='4056' tid='4055', class="m">::</a><a id='4058' tid='4057', class="m">StrDup</a>(<a id='4060' tid='4059', class="m">str</a>) : <a id='4062' tid='4061', class="m">str</a>);
}


<a id='3974' tid='3973', class="m">CounterMap</a><a id='3976' tid='3975', class="m">*</a> <a id='3978' tid='3977', class="m">Shell</a><a id='3980' tid='3979', class="m">::</a><a id='3982' tid='3981', class="m">counter_map_</a>;
<a id='3954' tid='3953', class="m">i</a><a id='3956' tid='3955', class="m">::</a><a id='3958' tid='3957', class="m">OS</a><a id='3960' tid='3959', class="m">::</a><a id='3962' tid='3961', class="m">MemoryMappedFile</a><a id='3964' tid='3963', class="m">*</a> <a id='3966' tid='3965', class="m">Shell</a><a id='3968' tid='3967', class="m">::</a><a id='3970' tid='3969', class="m">counters_file_</a> = <a id='3972' tid='3971', class="m">NULL</a>;
<span class="i">CounterCollection Shell::local_counters_;</span>
<a id='3940' tid='3939', class="m">CounterCollection</a><a id='3942' tid='3941', class="m">*</a> <a id='3944' tid='3943', class="m">Shell</a><a id='3946' tid='3945', class="m">::</a><a id='3948' tid='3947', class="m">counters_</a> = <a id='3950' tid='3949', class="m">&</a><a id='3952' tid='3951', class="m">local_counters_</a>;
<a id='3930' tid='3929', class="m">Persistent</a>&lt;<a id='3932' tid='3931', class="m">Context</a>&gt; <a id='3934' tid='3933', class="m">Shell</a><a id='3936' tid='3935', class="m">::</a><a id='3938' tid='3937', class="m">utility_context_</a>;
<a id='3920' tid='3919', class="m">Persistent</a>&lt;<a id='3922' tid='3921', class="m">Context</a>&gt; <a id='3924' tid='3923', class="m">Shell</a><a id='3926' tid='3925', class="m">::</a><a id='3928' tid='3927', class="m">evaluation_context_</a>;


<a id='3852' tid='3851', class="m">bool</a> <a id='3854' tid='3853', class="m">CounterMap</a><a id='3856' tid='3855', class="m">::</a><a id='3858' tid='3857', class="m">Match</a>(<a id='3860' tid='3859', class="m">void</a><a id='3862' tid='3861', class="m">*</a> <a id='3864' tid='3863', class="m">key1</a>, <a id='3866' tid='3865', class="m">void</a><a id='3868' tid='3867', class="m">*</a> <a id='3870' tid='3869', class="m">key2</a>) {
  <a id='3872' tid='3871', class="m">const</a> <a id='3874' tid='3873', class="m">char</a><a id='3876' tid='3875', class="m">*</a> <a id='3878' tid='3877', class="m">name1</a> = <a id='3880' tid='3879', class="m">reinterpret_cast</a>&lt;<a id='3882' tid='3881', class="m">const</a> <a id='3884' tid='3883', class="m">char</a><a id='3886' tid='3885', class="m">*</a>&gt;(<a id='3888' tid='3887', class="m">key1</a>);
  <a id='3890' tid='3889', class="m">const</a> <a id='3892' tid='3891', class="m">char</a><a id='3894' tid='3893', class="m">*</a> <a id='3896' tid='3895', class="m">name2</a> = <a id='3898' tid='3897', class="m">reinterpret_cast</a>&lt;<a id='3900' tid='3899', class="m">const</a> <a id='3902' tid='3901', class="m">char</a><a id='3904' tid='3903', class="m">*</a>&gt;(<a id='3906' tid='3905', class="m">key2</a>);
  <a id='3908' tid='3907', class="m">return</a> <a id='3910' tid='3909', class="m">strcmp</a>(<a id='3912' tid='3911', class="m">name1</a>, <a id='3914' tid='3913', class="m">name2</a>) <a id='3916' tid='3915', class="m">==</a> <a id='3918' tid='3917', class="m">0</a>;
}


  // Converts a V8 value to a C string.
<span class="i">const</span> <span class="i">char*</span> <span class="i">Shell::ToCString</span>(<a id='3836' tid='3835', class="m">const</a> <a id='3838' tid='3837', class="m">v8</a><a id='3840' tid='3839', class="m">::</a><a id='3842' tid='3841', class="m">String</a><a id='3844' tid='3843', class="m">::</a><a id='3846' tid='3845', class="m">Utf8Value</a><a id='3848' tid='3847', class="m">&</a> <a id='3850' tid='3849', class="m">value</a>) {
  <a id='3644' tid='3643', class="m">return</a> <a id='3646' tid='3645', class="m">*</a><a id='3648' tid='3647', class="m">value</a> ? <a id='3650' tid='3649', class="m">*</a><a id='3652' tid='3651', class="m">value</a> : <a id='3654' tid='3653', class="m">&quot;&lt;string conversion failed&gt;&quot;</a>;
}


// Executes a string within the current v8 context.
<a id='3656' tid='3655', class="m">bool</a> <a id='3658' tid='3657', class="m">Shell</a><a id='3660' tid='3659', class="m">::</a><a id='3662' tid='3661', class="m">ExecuteString</a>(<a id='3664' tid='3663', class="m">Handle</a>&lt;<a id='3666' tid='3665', class="m">String</a>&gt; <a id='3668' tid='3667', class="m">source</a>,
                          <a id='3670' tid='3669', class="m">Handle</a>&lt;<a id='3672' tid='3671', class="m">Value</a>&gt; <a id='3674' tid='3673', class="m">name</a>,
                          <a id='3676' tid='3675', class="m">bool</a> <a id='3678' tid='3677', class="m">print_result</a>,
                          <a id='3680' tid='3679', class="m">bool</a> <a id='3682' tid='3681', class="m">report_exceptions</a>) {
  <a id='3684' tid='3683', class="m">HandleScope</a> <a id='3686' tid='3685', class="m">handle_scope</a>;
  <a id='3688' tid='3687', class="m">TryCatch</a> <a id='3690' tid='3689', class="m">try_catch</a>;
  <a id='3692' tid='3691', class="m">if</a> (<a id='3694' tid='3693', class="m">i</a><a id='3696' tid='3695', class="m">::</a><a id='3698' tid='3697', class="m">FLAG_debugger</a>) {
    // When debugging make exceptions appear to be uncaught.
    <a id='3700' tid='3699', class="m">try_catch</a>.<a id='3702' tid='3701', class="m">SetVerbose</a>(<a id='3704' tid='3703', class="m">true</a>);
  }
  <a id='3706' tid='3705', class="m">Handle</a>&lt;<a id='3708' tid='3707', class="m">Script</a>&gt; <a id='3710' tid='3709', class="m">script</a> = <a id='3712' tid='3711', class="m">Script</a><a id='3714' tid='3713', class="m">::</a><a id='3716' tid='3715', class="m">Compile</a>(<a id='3718' tid='3717', class="m">source</a>, <a id='3720' tid='3719', class="m">name</a>);
  <a id='3722' tid='3721', class="m">if</a> (<a id='3724' tid='3723', class="m">script</a>.<a id='3726' tid='3725', class="m">IsEmpty</a>()) {
    // Print errors that happened during compilation.
    <a id='3728' tid='3727', class="m">if</a> (<a id='3730' tid='3729', class="m">report_exceptions</a> <a id='3732' tid='3731', class="m">&&</a> <a id='3734' tid='3733', class="m">!</a><a id='3736' tid='3735', class="m">i</a><a id='3738' tid='3737', class="m">::</a><a id='3740' tid='3739', class="m">FLAG_debugger</a>)
      <a id='3742' tid='3741', class="m">ReportException</a>(<a id='3744' tid='3743', class="m">&</a><a id='3746' tid='3745', class="m">try_catch</a>);
    <a id='3748' tid='3747', class="m">return</a> <a id='3750' tid='3749', class="m">false</a>;
  } <a id='3752' tid='3751', class="m">else</a> {
    <a id='3754' tid='3753', class="m">Handle</a>&lt;<a id='3756' tid='3755', class="m">Value</a>&gt; <a id='3758' tid='3757', class="m">result</a> = <a id='3760' tid='3759', class="m">script</a>-&gt;<a id='3762' tid='3761', class="m">Run</a>();
    <a id='3764' tid='3763', class="m">if</a> (<a id='3766' tid='3765', class="m">result</a>.<a id='3768' tid='3767', class="m">IsEmpty</a>()) {
      <span class="i">ASSERT(try_catch.HasCaught());</span>
      // Print errors that happened during execution.
      <a id='3770' tid='3769', class="m">if</a> (<a id='3772' tid='3771', class="m">report_exceptions</a> <a id='3774' tid='3773', class="m">&&</a> <a id='3776' tid='3775', class="m">!</a><a id='3778' tid='3777', class="m">i</a><a id='3780' tid='3779', class="m">::</a><a id='3782' tid='3781', class="m">FLAG_debugger</a>)
        <a id='3784' tid='3783', class="m">ReportException</a>(<a id='3786' tid='3785', class="m">&</a><a id='3788' tid='3787', class="m">try_catch</a>);
      <span class="i">return false;</span>
    } <a id='3790' tid='3789', class="m">else</a> {
      <span class="i">ASSERT(!try_catch.HasCaught());</span>
      <a id='3792' tid='3791', class="m">if</a> (<a id='3794' tid='3793', class="m">print_result</a> <a id='3796' tid='3795', class="m">&&</a> <a id='3798' tid='3797', class="m">!</a><a id='3800' tid='3799', class="m">result</a>-&gt;<a id='3802' tid='3801', class="m">IsUndefined</a>()) {
        // If all went well and the result wasn&#39;t undefined then print
        // the returned value.
        <a id='3804' tid='3803', class="m">v8</a><a id='3806' tid='3805', class="m">::</a><a id='3808' tid='3807', class="m">String</a><a id='3810' tid='3809', class="m">::</a><a id='3812' tid='3811', class="m">Utf8Value</a> <a id='3814' tid='3813', class="m">str</a>(<a id='3816' tid='3815', class="m">result</a>);
        <a id='3818' tid='3817', class="m">const</a> <a id='3820' tid='3819', class="m">char</a><a id='3822' tid='3821', class="m">*</a> <a id='3824' tid='3823', class="m">cstr</a> = <a id='3826' tid='3825', class="m">ToCString</a>(<a id='3828' tid='3827', class="m">str</a>);
        <a id='3830' tid='3829', class="m">printf</a>(<a id='3832' tid='3831', class="m">&quot;%s\n&quot;</a>, <a id='3834' tid='3833', class="m">cstr</a>);
      }
      <span class="i">return true;</span>
    }
  }
}


<a id='3608' tid='3607', class="m">Handle</a>&lt;<a id='3610' tid='3609', class="m">Value</a>&gt; <a id='3612' tid='3611', class="m">Shell</a><a id='3614' tid='3613', class="m">::</a><a id='3616' tid='3615', class="m">Print</a>(<a id='3618' tid='3617', class="m">const</a> <a id='3620' tid='3619', class="m">Arguments</a><a id='3622' tid='3621', class="m">&</a> <a id='3624' tid='3623', class="m">args</a>) {
  <a id='3626' tid='3625', class="m">Handle</a>&lt;<a id='3628' tid='3627', class="m">Value</a>&gt; <a id='3630' tid='3629', class="m">val</a> = <a id='3632' tid='3631', class="m">Write</a>(<a id='3634' tid='3633', class="m">args</a>);
  <a id='3636' tid='3635', class="m">printf</a>(<a id='3638' tid='3637', class="m">&quot;\n&quot;</a>);
  <a id='3640' tid='3639', class="m">return</a> <a id='3642' tid='3641', class="m">val</a>;
}


 <a id='3492' tid='3491', class="m">Handle</a>&lt;<a id='3494' tid='3493', class="m">Value</a>&gt; <a id='3496' tid='3495', class="m">Shell</a><a id='3498' tid='3497', class="m">::</a><a id='3500' tid='3499', class="m">Write</a>(<a id='3502' tid='3501', class="m">const</a> <a id='3504' tid='3503', class="m">Arguments</a><a id='3506' tid='3505', class="m">&</a> <a id='3508' tid='3507', class="m">args</a>) {
  <a id='3510' tid='3509', class="m">for</a> (<a id='3512' tid='3511', class="m">int</a> <a id='3514' tid='3513', class="m">i</a> = <a id='3516' tid='3515', class="m">0</a>; <a id='3518' tid='3517', class="m">i</a> <a id='3520' tid='3519', class="m">&lt;</a> <a id='3522' tid='3521', class="m">args</a>.<a id='3524' tid='3523', class="m">Length</a>(); <a id='3526' tid='3525', class="m">i</a><a id='3528' tid='3527', class="m">++</a>) {
    <a id='3530' tid='3529', class="m">HandleScope</a> <a id='3532' tid='3531', class="m">handle_scope</a>;
    <a id='3534' tid='3533', class="m">if</a> (<a id='3536' tid='3535', class="m">i</a> <a id='3538' tid='3537', class="m">!=</a> <a id='3540' tid='3539', class="m">0</a>) {
      <a id='3542' tid='3541', class="m">printf</a>(<a id='3544' tid='3543', class="m">&quot; &quot;</a>);
    }
    <a id='3546' tid='3545', class="m">v8</a><a id='3548' tid='3547', class="m">::</a><a id='3550' tid='3549', class="m">String</a><a id='3552' tid='3551', class="m">::</a><a id='3554' tid='3553', class="m">Utf8Value</a> <a id='3556' tid='3555', class="m">str</a>(<a id='3558' tid='3557', class="m">args</a>[<a id='3560' tid='3559', class="m">i</a>]);
     <a id='3562' tid='3561', class="m">int</a> <a id='3564' tid='3563', class="m">n</a> = <a id='3566' tid='3565', class="m">fwrite</a>(<a id='3568' tid='3567', class="m">*</a><a id='3570' tid='3569', class="m">str</a>, <a id='3572' tid='3571', class="m">sizeof</a>(<a id='3574' tid='3573', class="m">*</a><a id='3576' tid='3575', class="m">*</a><a id='3578' tid='3577', class="m">str</a>), <a id='3580' tid='3579', class="m">str</a>.<a id='3582' tid='3581', class="m">length</a>(), <a id='3584' tid='3583', class="m">stdout</a>);
    <a id='3586' tid='3585', class="m">if</a> (<a id='3588' tid='3587', class="m">n</a> <a id='3590' tid='3589', class="m">!=</a> <a id='3592' tid='3591', class="m">str</a>.<a id='3594' tid='3593', class="m">length</a>()) {
      <a id='3596' tid='3595', class="m">printf</a>(<a id='3598' tid='3597', class="m">&quot;Error in fwrite\n&quot;</a>);
      <a id='3600' tid='3599', class="m">exit</a>(<a id='3602' tid='3601', class="m">1</a>);
    }
  }
  <a id='3604' tid='3603', class="m">return</a> <a id='3606' tid='3605', class="m">Undefined</a>();
 }


 <a id='3406' tid='3405', class="m">Handle</a>&lt;<a id='3408' tid='3407', class="m">Value</a>&gt; <a id='3410' tid='3409', class="m">Shell</a><a id='3412' tid='3411', class="m">::</a><a id='3414' tid='3413', class="m">Read</a>(<a id='3416' tid='3415', class="m">const</a> <a id='3418' tid='3417', class="m">Arguments</a><a id='3420' tid='3419', class="m">&</a> <a id='3422' tid='3421', class="m">args</a>) {
  <a id='3424' tid='3423', class="m">String</a><a id='3426' tid='3425', class="m">::</a><a id='3428' tid='3427', class="m">Utf8Value</a> <a id='3430' tid='3429', class="m">file</a>(<a id='3432' tid='3431', class="m">args</a>[<a id='3434' tid='3433', class="m">0</a>]);
  <a id='3436' tid='3435', class="m">if</a> (<a id='3438' tid='3437', class="m">*</a><a id='3440' tid='3439', class="m">file</a> <a id='3442' tid='3441', class="m">==</a> <a id='3444' tid='3443', class="m">NULL</a>) {
   <a id='3446' tid='3445', class="m">return</a> <a id='3448' tid='3447', class="m">ThrowException</a>(<a id='3450' tid='3449', class="m">String</a><a id='3452' tid='3451', class="m">::</a><a id='3454' tid='3453', class="m">New</a>(<a id='3456' tid='3455', class="m">&quot;Error loading file&quot;</a>));
  }
  <a id='3458' tid='3457', class="m">Handle</a>&lt;<a id='3460' tid='3459', class="m">String</a>&gt; <a id='3462' tid='3461', class="m">source</a> = <a id='3464' tid='3463', class="m">ReadFile</a>(<a id='3466' tid='3465', class="m">*</a><a id='3468' tid='3467', class="m">file</a>);
  <a id='3470' tid='3469', class="m">if</a> (<a id='3472' tid='3471', class="m">source</a>.<a id='3474' tid='3473', class="m">IsEmpty</a>()) {
    <a id='3476' tid='3475', class="m">return</a> <a id='3478' tid='3477', class="m">ThrowException</a>(<a id='3480' tid='3479', class="m">String</a><a id='3482' tid='3481', class="m">::</a><a id='3484' tid='3483', class="m">New</a>(<a id='3486' tid='3485', class="m">&quot;Error loading file&quot;</a>));
  }
  <a id='3488' tid='3487', class="m">return</a> <a id='3490' tid='3489', class="m">source</a>;
 }


<a id='3306' tid='3305', class="m">Handle</a>&lt;<a id='3308' tid='3307', class="m">Value</a>&gt; <a id='3310' tid='3309', class="m">Shell</a><a id='3312' tid='3311', class="m">::</a><a id='3314' tid='3313', class="m">ReadLine</a>(<a id='3316' tid='3315', class="m">const</a> <a id='3318' tid='3317', class="m">Arguments</a><a id='3320' tid='3319', class="m">&</a> <a id='3322' tid='3321', class="m">args</a>) {
  <a id='3324' tid='3323', class="m">i</a><a id='3326' tid='3325', class="m">::</a><a id='3328' tid='3327', class="m">SmartPointer</a>&lt;<a id='3330' tid='3329', class="m">char</a>&gt; <a id='3332' tid='3331', class="m">line</a>(<a id='3334' tid='3333', class="m">i</a><a id='3336' tid='3335', class="m">::</a><a id='3338' tid='3337', class="m">ReadLine</a>(<a id='3340' tid='3339', class="m">&quot;&quot;</a>));
  <a id='3342' tid='3341', class="m">if</a> (<a id='3344' tid='3343', class="m">*</a><a id='3346' tid='3345', class="m">line</a> <a id='3348' tid='3347', class="m">==</a> <a id='3350' tid='3349', class="m">NULL</a>) {
    <a id='3352' tid='3351', class="m">return</a> <a id='3354' tid='3353', class="m">Null</a>();
  }
 <a id='3356' tid='3355', class="m">size_t</a> <a id='3358' tid='3357', class="m">len</a> = <a id='3360' tid='3359', class="m">strlen</a>(<a id='3362' tid='3361', class="m">*</a><a id='3364' tid='3363', class="m">line</a>);
  <a id='3366' tid='3365', class="m">if</a> (<a id='3368' tid='3367', class="m">len</a> <a id='3370' tid='3369', class="m">&gt;</a> <a id='3372' tid='3371', class="m">0</a> <a id='3374' tid='3373', class="m">&&</a> <a id='3376' tid='3375', class="m">line</a>[<a id='3378' tid='3377', class="m">len</a> <a id='3380' tid='3379', class="m">-</a> <a id='3382' tid='3381', class="m">1</a>] <a id='3384' tid='3383', class="m">==</a> <a id='3386' tid='3385', class="m">&#39;\n&#39;</a>) {
    <a id='3388' tid='3387', class="m">--</a><a id='3390' tid='3389', class="m">len</a>;
  }
  <a id='3392' tid='3391', class="m">return</a> <a id='3394' tid='3393', class="m">String</a><a id='3396' tid='3395', class="m">::</a><a id='3398' tid='3397', class="m">New</a>(<a id='3400' tid='3399', class="m">*</a><a id='3402' tid='3401', class="m">line</a>, <a id='3404' tid='3403', class="m">len</a>);
}


<a id='3162' tid='3161', class="m">Handle</a>&lt;<a id='3164' tid='3163', class="m">Value</a>&gt; <a id='3166' tid='3165', class="m">Shell</a><a id='3168' tid='3167', class="m">::</a><a id='3170' tid='3169', class="m">Load</a>(<a id='3172' tid='3171', class="m">const</a> <a id='3174' tid='3173', class="m">Arguments</a><a id='3176' tid='3175', class="m">&</a> <a id='3178' tid='3177', class="m">args</a>) {
  <a id='3180' tid='3179', class="m">for</a> (<a id='3182' tid='3181', class="m">int</a> <a id='3184' tid='3183', class="m">i</a> = <a id='3186' tid='3185', class="m">0</a>; <a id='3188' tid='3187', class="m">i</a> <a id='3190' tid='3189', class="m">&lt;</a> <a id='3192' tid='3191', class="m">args</a>.<a id='3194' tid='3193', class="m">Length</a>(); <a id='3196' tid='3195', class="m">i</a><a id='3198' tid='3197', class="m">++</a>) {
    <a id='3200' tid='3199', class="m">HandleScope</a> <a id='3202' tid='3201', class="m">handle_scope</a>;
    <a id='3204' tid='3203', class="m">String</a><a id='3206' tid='3205', class="m">::</a><a id='3208' tid='3207', class="m">Utf8Value</a> <a id='3210' tid='3209', class="m">file</a>(<a id='3212' tid='3211', class="m">args</a>[<a id='3214' tid='3213', class="m">i</a>]);
    <a id='3216' tid='3215', class="m">if</a> (<a id='3218' tid='3217', class="m">*</a><a id='3220' tid='3219', class="m">file</a> <a id='3222' tid='3221', class="m">==</a> <a id='3224' tid='3223', class="m">NULL</a>) {
      <a id='3226' tid='3225', class="m">return</a> <a id='3228' tid='3227', class="m">ThrowException</a>(<a id='3230' tid='3229', class="m">String</a><a id='3232' tid='3231', class="m">::</a><a id='3234' tid='3233', class="m">New</a>(<a id='3236' tid='3235', class="m">&quot;Error loading file&quot;</a>));
    }
    <a id='3238' tid='3237', class="m">Handle</a>&lt;<a id='3240' tid='3239', class="m">String</a>&gt; <a id='3242' tid='3241', class="m">source</a> = <a id='3244' tid='3243', class="m">ReadFile</a>(<a id='3246' tid='3245', class="m">*</a><a id='3248' tid='3247', class="m">file</a>);
    <a id='3250' tid='3249', class="m">if</a> (<a id='3252' tid='3251', class="m">source</a>.<a id='3254' tid='3253', class="m">IsEmpty</a>()) {
      <a id='3256' tid='3255', class="m">return</a> <a id='3258' tid='3257', class="m">ThrowException</a>(<a id='3260' tid='3259', class="m">String</a><a id='3262' tid='3261', class="m">::</a><a id='3264' tid='3263', class="m">New</a>(<a id='3266' tid='3265', class="m">&quot;Error loading file&quot;</a>));
    }
    <a id='3268' tid='3267', class="m">if</a> (<a id='3270' tid='3269', class="m">!</a><a id='3272' tid='3271', class="m">ExecuteString</a>(<a id='3274' tid='3273', class="m">source</a>, <a id='3276' tid='3275', class="m">String</a><a id='3278' tid='3277', class="m">::</a><a id='3280' tid='3279', class="m">New</a>(<a id='3282' tid='3281', class="m">*</a><a id='3284' tid='3283', class="m">file</a>), <a id='3286' tid='3285', class="m">false</a>, <a id='3288' tid='3287', class="m">false</a>)) {
      <a id='3290' tid='3289', class="m">return</a> <a id='3292' tid='3291', class="m">ThrowException</a>(<a id='3294' tid='3293', class="m">String</a><a id='3296' tid='3295', class="m">::</a><a id='3298' tid='3297', class="m">New</a>(<a id='3300' tid='3299', class="m">&quot;Error executing file&quot;</a>));
    }
  }
  <a id='3302' tid='3301', class="m">return</a> <a id='3304' tid='3303', class="m">Undefined</a>();
}


 <span class="i">Handle&lt;Value&gt; Shell::CreateExternalArray(const Arguments& args,
                                         ExternalArrayType type,
                                         int element_size) {
  if (args.Length() != 1) {
    return ThrowException(
        String::New(&quot;Array constructor needs one parameter.&quot;));
  }
  int length = args[0]-&gt;Int32Value();
  void* data = malloc(length * element_size);
  memset(data, 0, length * element_size);
  Handle&lt;Object&gt; array = Object::New();
  Persistent&lt;Object&gt; persistent_array = Persistent&lt;Object&gt;::New(array);
  persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
  persistent_array.MarkIndependent();
  array-&gt;SetIndexedPropertiesToExternalArrayData(data, type, length);
  array-&gt;Set(String::New(&quot;length&quot;), Int32::New(length), ReadOnly);
  array-&gt;Set(String::New(&quot;BYTES_PER_ELEMENT&quot;), Int32::New(element_size));
  return array;
 }</span>


<span class="i">void Shell::ExternalArrayWeakCallback(Persistent&lt;Value&gt; object, void* data) {
  free(data);
  object.Dispose();
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Int8Array(const Arguments& args) {
  return CreateExternalArray(args, v8::kExternalByteArray, sizeof(int8_t));
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Uint8Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalUnsignedByteArray, sizeof(uint8_t));
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Int16Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalShortArray, sizeof(int16_t));
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Uint16Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalUnsignedShortArray,
                             sizeof(uint16_t));
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Int32Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalIntArray, sizeof(int32_t));
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Uint32Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalUnsignedIntArray, sizeof(uint32_t));
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Float32Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalFloatArray,
                             sizeof(float));  // NOLINT
}</span>


<span class="i">Handle&lt;Value&gt; Shell::Float64Array(const Arguments& args) {
  return CreateExternalArray(args, kExternalDoubleArray,
                             sizeof(double));  // NOLINT
}</span>


<span class="i">Handle&lt;Value&gt; Shell::PixelArray(const Arguments& args) {
  return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t));
}</span>


<a id='3132' tid='3131', class="m">Handle</a>&lt;<a id='3134' tid='3133', class="m">Value</a>&gt; <a id='3136' tid='3135', class="m">Shell</a><a id='3138' tid='3137', class="m">::</a><a id='3140' tid='3139', class="m">Yield</a>(<a id='3142' tid='3141', class="m">const</a> <a id='3144' tid='3143', class="m">Arguments</a><a id='3146' tid='3145', class="m">&</a> <a id='3148' tid='3147', class="m">args</a>) {
  <a id='3150' tid='3149', class="m">v8</a><a id='3152' tid='3151', class="m">::</a><a id='3154' tid='3153', class="m">Unlocker</a> <a id='3156' tid='3155', class="m">unlocker</a>;
  <a id='3158' tid='3157', class="m">return</a> <a id='3160' tid='3159', class="m">Undefined</a>();
}


<a id='3094' tid='3093', class="m">Handle</a>&lt;<a id='3096' tid='3095', class="m">Value</a>&gt; <a id='3098' tid='3097', class="m">Shell</a><a id='3100' tid='3099', class="m">::</a><a id='3102' tid='3101', class="m">Quit</a>(<a id='3104' tid='3103', class="m">const</a> <a id='3106' tid='3105', class="m">Arguments</a><a id='3108' tid='3107', class="m">&</a> <a id='3110' tid='3109', class="m">args</a>) {
  <a id='3112' tid='3111', class="m">int</a> <a id='3114' tid='3113', class="m">exit_code</a> = <a id='3116' tid='3115', class="m">args</a>[<a id='3118' tid='3117', class="m">0</a>]-&gt;<a id='3120' tid='3119', class="m">Int32Value</a>();
  <a id='3122' tid='3121', class="m">OnExit</a>();
  <a id='3124' tid='3123', class="m">exit</a>(<a id='3126' tid='3125', class="m">exit_code</a>);
  <a id='3128' tid='3127', class="m">return</a> <a id='3130' tid='3129', class="m">Undefined</a>();
}


<a id='3062' tid='3061', class="m">Handle</a>&lt;<a id='3064' tid='3063', class="m">Value</a>&gt; <a id='3066' tid='3065', class="m">Shell</a><a id='3068' tid='3067', class="m">::</a><a id='3070' tid='3069', class="m">Version</a>(<a id='3072' tid='3071', class="m">const</a> <a id='3074' tid='3073', class="m">Arguments</a><a id='3076' tid='3075', class="m">&</a> <a id='3078' tid='3077', class="m">args</a>) {
  <a id='3080' tid='3079', class="m">return</a> <a id='3082' tid='3081', class="m">String</a><a id='3084' tid='3083', class="m">::</a><a id='3086' tid='3085', class="m">New</a>(<a id='3088' tid='3087', class="m">V8</a><a id='3090' tid='3089', class="m">::</a><a id='3092' tid='3091', class="m">GetVersion</a>());
}


<a id='2972' tid='2971', class="m">void</a> <a id='2974' tid='2973', class="m">Shell</a><a id='2976' tid='2975', class="m">::</a><a id='2978' tid='2977', class="m">ReportException</a>(<a id='2980' tid='2979', class="m">v8</a><a id='2982' tid='2981', class="m">::</a><a id='2984' tid='2983', class="m">TryCatch</a><a id='2986' tid='2985', class="m">*</a> <a id='2988' tid='2987', class="m">try_catch</a>) {
  <a id='2990' tid='2989', class="m">HandleScope</a> <a id='2992' tid='2991', class="m">handle_scope</a>;
  <a id='2994' tid='2993', class="m">v8</a><a id='2996' tid='2995', class="m">::</a><a id='2998' tid='2997', class="m">String</a><a id='3000' tid='2999', class="m">::</a><a id='3002' tid='3001', class="m">Utf8Value</a> <a id='3004' tid='3003', class="m">exception</a>(<a id='3006' tid='3005', class="m">try_catch</a>-&gt;<a id='3008' tid='3007', class="m">Exception</a>());
  <a id='3010' tid='3009', class="m">const</a> <a id='3012' tid='3011', class="m">char</a><a id='3014' tid='3013', class="m">*</a> <a id='3016' tid='3015', class="m">exception_string</a> = <a id='3018' tid='3017', class="m">ToCString</a>(<a id='3020' tid='3019', class="m">exception</a>);
  <a id='3022' tid='3021', class="m">Handle</a>&lt;<a id='3024' tid='3023', class="m">Message</a>&gt; <a id='3026' tid='3025', class="m">message</a> = <a id='3028' tid='3027', class="m">try_catch</a>-&gt;<a id='3030' tid='3029', class="m">Message</a>();
  <a id='3032' tid='3031', class="m">if</a> (<a id='3034' tid='3033', class="m">message</a>.<a id='3036' tid='3035', class="m">IsEmpty</a>()) {
    // V8 didn&#39;t provide any extra information about this error; just
    // print the exception.
    <a id='3038' tid='3037', class="m">printf</a>(<a id='3040' tid='3039', class="m">&quot;%s\n&quot;</a>, <a id='3042' tid='3041', class="m">exception_string</a>);
  } <a id='3044' tid='3043', class="m">else</a> {
    // Print (filename):(line number): (message).
    <a id='3046' tid='3045', class="m">v8</a><a id='3048' tid='3047', class="m">::</a><a id='3050' tid='3049', class="m">String</a><a id='3052' tid='3051', class="m">::</a><a id='3054' tid='3053', class="m">Utf8Value</a> <a id='3056' tid='3055', class="m">filename</a>(<a id='3058' tid='3057', class="m">message</a>-&gt;<a id='3060' tid='3059', class="m">GetScriptResourceName</a>());
    <a id='2960' tid='2959', class="m">const</a> <a id='2962' tid='2961', class="m">char</a><a id='2964' tid='2963', class="m">*</a> <a id='2966' tid='2965', class="m">filename_string</a> = <a id='2968' tid='2967', class="m">ToCString</a>(<a id='2970' tid='2969', class="m">filename</a>);
    <span class="i">int linenum = message-&gt;GetLineNumber();</span>
    <a id='2820' tid='2819', class="m">printf</a>(<a id='2822' tid='2821', class="m">&quot;%s:%i: %s\n&quot;</a>, <a id='2824' tid='2823', class="m">filename_string</a>, <a id='2826' tid='2825', class="m">linenum</a>, <a id='2828' tid='2827', class="m">exception_string</a>);
    // Print line of source code.
    <a id='2694' tid='2693', class="m">v8</a><a id='2696' tid='2695', class="m">::</a><a id='2698' tid='2697', class="m">String</a><a id='2700' tid='2699', class="m">::</a><a id='2702' tid='2701', class="m">Utf8Value</a> <a id='2704' tid='2703', class="m">sourceline</a>(<a id='2706' tid='2705', class="m">message</a>-&gt;<a id='2708' tid='2707', class="m">GetSourceLine</a>());
    <a id='2580' tid='2579', class="m">const</a> <a id='2582' tid='2581', class="m">char</a><a id='2584' tid='2583', class="m">*</a> <a id='2586' tid='2585', class="m">sourceline_string</a> = <a id='2588' tid='2587', class="m">ToCString</a>(<a id='2590' tid='2589', class="m">sourceline</a>);
    <span class="i">printf(&quot;%s\n&quot;, sourceline_string);</span>
    // Print wavy underline (GetUnderline is deprecated).
    <span class="i">int start = message-&gt;GetStartColumn();</span>
    <a id='2472' tid='2471', class="m">for</a> (<a id='2474' tid='2473', class="m">int</a> <a id='2476' tid='2475', class="m">i</a> = <a id='2478' tid='2477', class="m">0</a>; <a id='2480' tid='2479', class="m">i</a> <a id='2482' tid='2481', class="m">&lt;</a> <a id='2484' tid='2483', class="m">start</a>; <a id='2486' tid='2485', class="m">i</a><a id='2488' tid='2487', class="m">++</a>) {
      <a id='2490' tid='2489', class="m">printf</a>(<a id='2492' tid='2491', class="m">&quot; &quot;</a>);
    }
    <span class="i">int end = message-&gt;GetEndColumn();</span>
    <a id='2428' tid='2427', class="m">for</a> (<a id='2430' tid='2429', class="m">int</a> <a id='2432' tid='2431', class="m">i</a> = <a id='2434' tid='2433', class="m">start</a>; <a id='2436' tid='2435', class="m">i</a> <a id='2438' tid='2437', class="m">&lt;</a> <a id='2440' tid='2439', class="m">end</a>; <a id='2442' tid='2441', class="m">i</a><a id='2444' tid='2443', class="m">++</a>) {
      <a id='2446' tid='2445', class="m">printf</a>(<a id='2448' tid='2447', class="m">&quot;^&quot;</a>);
    }
    <span class="i">printf(&quot;\n&quot;);</span>
    <span class="i">v8::String::Utf8Value stack_trace(try_catch-&gt;StackTrace());</span>
    <span class="i">if (stack_trace.length() &gt; 0) {
      const char* stack_trace_string = ToCString(stack_trace);
      printf(&quot;%s\n&quot;, stack_trace_string);
    }</span>
  }
}


<a id='2830' tid='2829', class="m">Handle</a>&lt;<a id='2832' tid='2831', class="m">Array</a>&gt; <a id='2834' tid='2833', class="m">Shell</a><a id='2836' tid='2835', class="m">::</a><a id='2838' tid='2837', class="m">GetCompletions</a>(<a id='2840' tid='2839', class="m">Handle</a>&lt;<a id='2842' tid='2841', class="m">String</a>&gt; <a id='2844' tid='2843', class="m">text</a>, <a id='2846' tid='2845', class="m">Handle</a>&lt;<a id='2848' tid='2847', class="m">String</a>&gt; <a id='2850' tid='2849', class="m">full</a>) {
  <a id='2862' tid='2861', class="m">HandleScope</a> <a id='2864' tid='2863', class="m">handle_scope</a>;
  <a id='2852' tid='2851', class="m">Context</a><a id='2854' tid='2853', class="m">::</a><a id='2856' tid='2855', class="m">Scope</a> <a id='2858' tid='2857', class="m">context_scope</a>(<a id='2860' tid='2859', class="m">utility_context_</a>);
  <a id='2866' tid='2865', class="m">Handle</a>&lt;<a id='2868' tid='2867', class="m">Object</a>&gt; <a id='2870' tid='2869', class="m">global</a> = <a id='2872' tid='2871', class="m">utility_context_</a>-&gt;<a id='2874' tid='2873', class="m">Global</a>();
  <a id='2876' tid='2875', class="m">Handle</a>&lt;<a id='2878' tid='2877', class="m">Value</a>&gt; <a id='2880' tid='2879', class="m">fun</a> = <a id='2882' tid='2881', class="m">global</a>-&gt;<a id='2884' tid='2883', class="m">Get</a>(<a id='2886' tid='2885', class="m">String</a><a id='2888' tid='2887', class="m">::</a><a id='2890' tid='2889', class="m">New</a>(<a id='2892' tid='2891', class="m">&quot;GetCompletions&quot;</a>));
  <a id='2894' tid='2893', class="m">static</a> <a id='2896' tid='2895', class="m">const</a> <a id='2898' tid='2897', class="m">int</a> <a id='2900' tid='2899', class="m">kArgc</a> = <a id='2902' tid='2901', class="m">3</a>;
  <a id='2904' tid='2903', class="m">Handle</a>&lt;<a id='2906' tid='2905', class="m">Value</a>&gt; <a id='2908' tid='2907', class="m">argv</a>[<a id='2910' tid='2909', class="m">kArgc</a>] = { <a id='2912' tid='2911', class="m">evaluation_context_</a>-&gt;<a id='2914' tid='2913', class="m">Global</a>(), <a id='2916' tid='2915', class="m">text</a>, <a id='2918' tid='2917', class="m">full</a> };
  <a id='2920' tid='2919', class="m">Handle</a>&lt;<a id='2922' tid='2921', class="m">Value</a>&gt; <a id='2924' tid='2923', class="m">val</a> = <a id='2926' tid='2925', class="m">Handle</a>&lt;<a id='2928' tid='2927', class="m">Function</a>&gt;<a id='2930' tid='2929', class="m">::</a><a id='2932' tid='2931', class="m">Cast</a>(<a id='2934' tid='2933', class="m">fun</a>)-&gt;<a id='2936' tid='2935', class="m">Call</a>(<a id='2938' tid='2937', class="m">global</a>, <a id='2940' tid='2939', class="m">kArgc</a>, <a id='2942' tid='2941', class="m">argv</a>);
  <a id='2944' tid='2943', class="m">return</a> <a id='2946' tid='2945', class="m">handle_scope</a>.<a id='2948' tid='2947', class="m">Close</a>(<a id='2950' tid='2949', class="m">Handle</a>&lt;<a id='2952' tid='2951', class="m">Array</a>&gt;<a id='2954' tid='2953', class="m">::</a><a id='2956' tid='2955', class="m">Cast</a>(<a id='2958' tid='2957', class="m">val</a>));
}


<span class="i">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
<a id='2710' tid='2709', class="m">Handle</a>&lt;<a id='2712' tid='2711', class="m">Object</a>&gt; <a id='2714' tid='2713', class="m">Shell</a><a id='2716' tid='2715', class="m">::</a><a id='2718' tid='2717', class="m">DebugMessageDetails</a>(<a id='2720' tid='2719', class="m">Handle</a>&lt;<a id='2722' tid='2721', class="m">String</a>&gt; <a id='2724' tid='2723', class="m">message</a>) {
  <a id='2726' tid='2725', class="m">Context</a><a id='2728' tid='2727', class="m">::</a><a id='2730' tid='2729', class="m">Scope</a> <a id='2732' tid='2731', class="m">context_scope</a>(<a id='2734' tid='2733', class="m">utility_context_</a>);
  <a id='2736' tid='2735', class="m">Handle</a>&lt;<a id='2738' tid='2737', class="m">Object</a>&gt; <a id='2740' tid='2739', class="m">global</a> = <a id='2742' tid='2741', class="m">utility_context_</a>-&gt;<a id='2744' tid='2743', class="m">Global</a>();
  <a id='2746' tid='2745', class="m">Handle</a>&lt;<a id='2748' tid='2747', class="m">Value</a>&gt; <a id='2750' tid='2749', class="m">fun</a> = <a id='2752' tid='2751', class="m">global</a>-&gt;<a id='2754' tid='2753', class="m">Get</a>(<a id='2756' tid='2755', class="m">String</a><a id='2758' tid='2757', class="m">::</a><a id='2760' tid='2759', class="m">New</a>(<a id='2762' tid='2761', class="m">&quot;DebugMessageDetails&quot;</a>));
  <a id='2764' tid='2763', class="m">static</a> <a id='2766' tid='2765', class="m">const</a> <a id='2768' tid='2767', class="m">int</a> <a id='2770' tid='2769', class="m">kArgc</a> = <a id='2772' tid='2771', class="m">1</a>;
  <a id='2774' tid='2773', class="m">Handle</a>&lt;<a id='2776' tid='2775', class="m">Value</a>&gt; <a id='2778' tid='2777', class="m">argv</a>[<a id='2780' tid='2779', class="m">kArgc</a>] = { <a id='2782' tid='2781', class="m">message</a> };
  <a id='2784' tid='2783', class="m">Handle</a>&lt;<a id='2786' tid='2785', class="m">Value</a>&gt; <a id='2788' tid='2787', class="m">val</a> = <a id='2790' tid='2789', class="m">Handle</a>&lt;<a id='2792' tid='2791', class="m">Function</a>&gt;<a id='2794' tid='2793', class="m">::</a><a id='2796' tid='2795', class="m">Cast</a>(<a id='2798' tid='2797', class="m">fun</a>)-&gt;<a id='2800' tid='2799', class="m">Call</a>(<a id='2802' tid='2801', class="m">global</a>, <a id='2804' tid='2803', class="m">kArgc</a>, <a id='2806' tid='2805', class="m">argv</a>);
  <a id='2808' tid='2807', class="m">return</a> <a id='2810' tid='2809', class="m">Handle</a>&lt;<a id='2812' tid='2811', class="m">Object</a>&gt;<a id='2814' tid='2813', class="m">::</a><a id='2816' tid='2815', class="m">Cast</a>(<a id='2818' tid='2817', class="m">val</a>);
}


<a id='2592' tid='2591', class="m">Handle</a>&lt;<a id='2594' tid='2593', class="m">Value</a>&gt; <a id='2596' tid='2595', class="m">Shell</a><a id='2598' tid='2597', class="m">::</a><a id='2600' tid='2599', class="m">DebugCommandToJSONRequest</a>(<a id='2602' tid='2601', class="m">Handle</a>&lt;<a id='2604' tid='2603', class="m">String</a>&gt; <a id='2606' tid='2605', class="m">command</a>) {
  <a id='2608' tid='2607', class="m">Context</a><a id='2610' tid='2609', class="m">::</a><a id='2612' tid='2611', class="m">Scope</a> <a id='2614' tid='2613', class="m">context_scope</a>(<a id='2616' tid='2615', class="m">utility_context_</a>);
  <a id='2618' tid='2617', class="m">Handle</a>&lt;<a id='2620' tid='2619', class="m">Object</a>&gt; <a id='2622' tid='2621', class="m">global</a> = <a id='2624' tid='2623', class="m">utility_context_</a>-&gt;<a id='2626' tid='2625', class="m">Global</a>();
  <a id='2628' tid='2627', class="m">Handle</a>&lt;<a id='2630' tid='2629', class="m">Value</a>&gt; <a id='2632' tid='2631', class="m">fun</a> = <a id='2634' tid='2633', class="m">global</a>-&gt;<a id='2636' tid='2635', class="m">Get</a>(<a id='2638' tid='2637', class="m">String</a><a id='2640' tid='2639', class="m">::</a><a id='2642' tid='2641', class="m">New</a>(<a id='2644' tid='2643', class="m">&quot;DebugCommandToJSONRequest&quot;</a>));
  <a id='2646' tid='2645', class="m">static</a> <a id='2648' tid='2647', class="m">const</a> <a id='2650' tid='2649', class="m">int</a> <a id='2652' tid='2651', class="m">kArgc</a> = <a id='2654' tid='2653', class="m">1</a>;
  <a id='2656' tid='2655', class="m">Handle</a>&lt;<a id='2658' tid='2657', class="m">Value</a>&gt; <a id='2660' tid='2659', class="m">argv</a>[<a id='2662' tid='2661', class="m">kArgc</a>] = { <a id='2664' tid='2663', class="m">command</a> };
  <a id='2666' tid='2665', class="m">Handle</a>&lt;<a id='2668' tid='2667', class="m">Value</a>&gt; <a id='2670' tid='2669', class="m">val</a> = <a id='2672' tid='2671', class="m">Handle</a>&lt;<a id='2674' tid='2673', class="m">Function</a>&gt;<a id='2676' tid='2675', class="m">::</a><a id='2678' tid='2677', class="m">Cast</a>(<a id='2680' tid='2679', class="m">fun</a>)-&gt;<a id='2682' tid='2681', class="m">Call</a>(<a id='2684' tid='2683', class="m">global</a>, <a id='2686' tid='2685', class="m">kArgc</a>, <a id='2688' tid='2687', class="m">argv</a>);
  <a id='2690' tid='2689', class="m">return</a> <a id='2692' tid='2691', class="m">val</a>;
}
<span class="i">#endif</span>


<a id='2494' tid='2493', class="m">int32_t</a><a id='2496' tid='2495', class="m">*</a> <a id='2498' tid='2497', class="m">Counter</a><a id='2500' tid='2499', class="m">::</a><a id='2502' tid='2501', class="m">Bind</a>(<a id='2504' tid='2503', class="m">const</a> <a id='2506' tid='2505', class="m">char</a><a id='2508' tid='2507', class="m">*</a> <a id='2510' tid='2509', class="m">name</a>, <a id='2512' tid='2511', class="m">bool</a> <a id='2514' tid='2513', class="m">is_histogram</a>) {
  <a id='2516' tid='2515', class="m">int</a> <a id='2518' tid='2517', class="m">i</a>;
  <a id='2520' tid='2519', class="m">for</a> (<a id='2522' tid='2521', class="m">i</a> <a id='2524' tid='2523', class="m">=</a> <a id='2526' tid='2525', class="m">0</a>; <a id='2528' tid='2527', class="m">i</a> <a id='2530' tid='2529', class="m">&lt;</a> <a id='2532' tid='2531', class="m">kMaxNameSize</a> <a id='2534' tid='2533', class="m">-</a> <a id='2536' tid='2535', class="m">1</a> <a id='2538' tid='2537', class="m">&&</a> <a id='2540' tid='2539', class="m">name</a>[<a id='2542' tid='2541', class="m">i</a>]; <a id='2544' tid='2543', class="m">i</a><a id='2546' tid='2545', class="m">++</a>)
    <a id='2548' tid='2547', class="m">name_</a>[<a id='2550' tid='2549', class="m">i</a>] <a id='2552' tid='2551', class="m">=</a> <a id='2554' tid='2553', class="m">static_cast</a>&lt;<a id='2556' tid='2555', class="m">char</a>&gt;(<a id='2558' tid='2557', class="m">name</a>[<a id='2560' tid='2559', class="m">i</a>]);
  <a id='2562' tid='2561', class="m">name_</a>[<a id='2564' tid='2563', class="m">i</a>] <a id='2566' tid='2565', class="m">=</a> <a id='2568' tid='2567', class="m">&#39;\0&#39;</a>;
  <a id='2570' tid='2569', class="m">is_histogram_</a> <a id='2572' tid='2571', class="m">=</a> <a id='2574' tid='2573', class="m">is_histogram</a>;
  <a id='2576' tid='2575', class="m">return</a> <a id='2578' tid='2577', class="m">ptr</a>();
}


<a id='2450' tid='2449', class="m">void</a> <a id='2452' tid='2451', class="m">Counter</a><a id='2454' tid='2453', class="m">::</a><a id='2456' tid='2455', class="m">AddSample</a>(<a id='2458' tid='2457', class="m">int32_t</a> <a id='2460' tid='2459', class="m">sample</a>) {
  <a id='2462' tid='2461', class="m">count_</a><a id='2464' tid='2463', class="m">++</a>;
  <a id='2466' tid='2465', class="m">sample_total_</a> <a id='2468' tid='2467', class="m">+=</a> <a id='2470' tid='2469', class="m">sample</a>;
}


<a id='2394' tid='2393', class="m">CounterCollection</a><a id='2396' tid='2395', class="m">::</a><a id='2398' tid='2397', class="m">CounterCollection</a>() {
  <a id='2400' tid='2399', class="m">magic_number_</a> <a id='2402' tid='2401', class="m">=</a> <a id='2404' tid='2403', class="m">0xDEADFACE</a>;
  <a id='2406' tid='2405', class="m">max_counters_</a> <a id='2408' tid='2407', class="m">=</a> <a id='2410' tid='2409', class="m">kMaxCounters</a>;
  <a id='2412' tid='2411', class="m">max_name_size_</a> <a id='2414' tid='2413', class="m">=</a> <a id='2416' tid='2415', class="m">Counter</a><a id='2418' tid='2417', class="m">::</a><a id='2420' tid='2419', class="m">kMaxNameSize</a>;
  <a id='2422' tid='2421', class="m">counters_in_use_</a> <a id='2424' tid='2423', class="m">=</a> <a id='2426' tid='2425', class="m">0</a>;
}


<a id='2362' tid='2361', class="m">Counter</a><a id='2364' tid='2363', class="m">*</a> <a id='2366' tid='2365', class="m">CounterCollection</a><a id='2368' tid='2367', class="m">::</a><a id='2370' tid='2369', class="m">GetNextCounter</a>() {
  <a id='2372' tid='2371', class="m">if</a> (<a id='2374' tid='2373', class="m">counters_in_use_</a> <a id='2376' tid='2375', class="m">==</a> <a id='2378' tid='2377', class="m">kMaxCounters</a>) <a id='2380' tid='2379', class="m">return</a> <a id='2382' tid='2381', class="m">NULL</a>;
  <a id='2384' tid='2383', class="m">return</a> <a id='2386' tid='2385', class="m">&</a><a id='2388' tid='2387', class="m">counters_</a>[<a id='2390' tid='2389', class="m">counters_in_use_</a><a id='2392' tid='2391', class="m">++</a>];
}


<a id='2246' tid='2245', class="m">void</a> <a id='2248' tid='2247', class="m">Shell</a><a id='2250' tid='2249', class="m">::</a><a id='2252' tid='2251', class="m">MapCounters</a>(<a id='2254' tid='2253', class="m">const</a> <a id='2256' tid='2255', class="m">char</a><a id='2258' tid='2257', class="m">*</a> <a id='2260' tid='2259', class="m">name</a>) {
  <a id='2262' tid='2261', class="m">counters_file_</a> <a id='2264' tid='2263', class="m">=</a> <a id='2266' tid='2265', class="m">i</a><a id='2268' tid='2267', class="m">::</a><a id='2270' tid='2269', class="m">OS</a><a id='2272' tid='2271', class="m">::</a><a id='2274' tid='2273', class="m">MemoryMappedFile</a><a id='2276' tid='2275', class="m">::</a><a id='2278' tid='2277', class="m">create</a>(<a id='2280' tid='2279', class="m">name</a>,
    <a id='2282' tid='2281', class="m">sizeof</a>(<a id='2284' tid='2283', class="m">CounterCollection</a>), <a id='2286' tid='2285', class="m">&</a><a id='2288' tid='2287', class="m">local_counters_</a>);
  <a id='2290' tid='2289', class="m">void</a><a id='2292' tid='2291', class="m">*</a> <a id='2294' tid='2293', class="m">memory</a> = (<a id='2296' tid='2295', class="m">counters_file_</a> <a id='2298' tid='2297', class="m">==</a> <a id='2300' tid='2299', class="m">NULL</a>) ?
      <a id='2302' tid='2301', class="m">NULL</a> : <a id='2304' tid='2303', class="m">counters_file_</a>-&gt;<a id='2306' tid='2305', class="m">memory</a>();
  <a id='2308' tid='2307', class="m">if</a> (<a id='2310' tid='2309', class="m">memory</a> <a id='2312' tid='2311', class="m">==</a> <a id='2314' tid='2313', class="m">NULL</a>) {
    <a id='2316' tid='2315', class="m">printf</a>(<a id='2318' tid='2317', class="m">&quot;Could not map counters file %s\n&quot;</a>, <a id='2320' tid='2319', class="m">name</a>);
    <a id='2322' tid='2321', class="m">exit</a>(<a id='2324' tid='2323', class="m">1</a>);
  }
  <a id='2326' tid='2325', class="m">counters_</a> <a id='2328' tid='2327', class="m">=</a> <a id='2330' tid='2329', class="m">static_cast</a>&lt;<a id='2332' tid='2331', class="m">CounterCollection</a><a id='2334' tid='2333', class="m">*</a>&gt;(<a id='2336' tid='2335', class="m">memory</a>);
  <a id='2338' tid='2337', class="m">V8</a><a id='2340' tid='2339', class="m">::</a><a id='2342' tid='2341', class="m">SetCounterFunction</a>(<a id='2344' tid='2343', class="m">LookupCounter</a>);
  <a id='2346' tid='2345', class="m">V8</a><a id='2348' tid='2347', class="m">::</a><a id='2350' tid='2349', class="m">SetCreateHistogramFunction</a>(<a id='2352' tid='2351', class="m">CreateHistogram</a>);
  <a id='2354' tid='2353', class="m">V8</a><a id='2356' tid='2355', class="m">::</a><a id='2358' tid='2357', class="m">SetAddHistogramSampleFunction</a>(<a id='2360' tid='2359', class="m">AddHistogramSample</a>);
}


<a id='2184' tid='2183', class="m">int</a> <a id='2186' tid='2185', class="m">CounterMap</a><a id='2188' tid='2187', class="m">::</a><a id='2190' tid='2189', class="m">Hash</a>(<a id='2192' tid='2191', class="m">const</a> <a id='2194' tid='2193', class="m">char</a><a id='2196' tid='2195', class="m">*</a> <a id='2198' tid='2197', class="m">name</a>) {
  <a id='2200' tid='2199', class="m">int</a> <a id='2202' tid='2201', class="m">h</a> = <a id='2204' tid='2203', class="m">0</a>;
  <a id='2206' tid='2205', class="m">int</a> <a id='2208' tid='2207', class="m">c</a>;
  <a id='2210' tid='2209', class="m">while</a> ((<a id='2212' tid='2211', class="m">c</a> <a id='2214' tid='2213', class="m">=</a> <a id='2216' tid='2215', class="m">*</a><a id='2218' tid='2217', class="m">name</a><a id='2220' tid='2219', class="m">++</a>) <a id='2222' tid='2221', class="m">!=</a> <a id='2224' tid='2223', class="m">0</a>) {
    <a id='2226' tid='2225', class="m">h</a> <a id='2228' tid='2227', class="m">+=</a> <a id='2230' tid='2229', class="m">h</a> <a id='2232' tid='2231', class="m">&lt;&lt;</a> <a id='2234' tid='2233', class="m">5</a>;
    <a id='2236' tid='2235', class="m">h</a> <a id='2238' tid='2237', class="m">+=</a> <a id='2240' tid='2239', class="m">c</a>;
  }
  <a id='2242' tid='2241', class="m">return</a> <a id='2244' tid='2243', class="m">h</a>;
}


<a id='2094' tid='2093', class="m">Counter</a><a id='2096' tid='2095', class="m">*</a> <a id='2098' tid='2097', class="m">Shell</a><a id='2100' tid='2099', class="m">::</a><a id='2102' tid='2101', class="m">GetCounter</a>(<a id='2104' tid='2103', class="m">const</a> <a id='2106' tid='2105', class="m">char</a><a id='2108' tid='2107', class="m">*</a> <a id='2110' tid='2109', class="m">name</a>, <a id='2112' tid='2111', class="m">bool</a> <a id='2114' tid='2113', class="m">is_histogram</a>) {
  <a id='2116' tid='2115', class="m">Counter</a><a id='2118' tid='2117', class="m">*</a> <a id='2120' tid='2119', class="m">counter</a> = <a id='2122' tid='2121', class="m">counter_map_</a>-&gt;<a id='2124' tid='2123', class="m">Lookup</a>(<a id='2126' tid='2125', class="m">name</a>);

  <a id='2128' tid='2127', class="m">if</a> (<a id='2130' tid='2129', class="m">counter</a> <a id='2132' tid='2131', class="m">==</a> <a id='2134' tid='2133', class="m">NULL</a>) {
    <a id='2136' tid='2135', class="m">counter</a> <a id='2138' tid='2137', class="m">=</a> <a id='2140' tid='2139', class="m">counters_</a>-&gt;<a id='2142' tid='2141', class="m">GetNextCounter</a>();
    <a id='2144' tid='2143', class="m">if</a> (<a id='2146' tid='2145', class="m">counter</a> <a id='2148' tid='2147', class="m">!=</a> <a id='2150' tid='2149', class="m">NULL</a>) {
      <a id='2152' tid='2151', class="m">counter_map_</a>-&gt;<a id='2154' tid='2153', class="m">Set</a>(<a id='2156' tid='2155', class="m">name</a>, <a id='2158' tid='2157', class="m">counter</a>);
      <a id='2160' tid='2159', class="m">counter</a>-&gt;<a id='2162' tid='2161', class="m">Bind</a>(<a id='2164' tid='2163', class="m">name</a>, <a id='2166' tid='2165', class="m">is_histogram</a>);
    }
  } <a id='2168' tid='2167', class="m">else</a> {
    <a id='2170' tid='2169', class="m">ASSERT</a>(<a id='2172' tid='2171', class="m">counter</a>-&gt;<a id='2174' tid='2173', class="m">is_histogram</a>() <a id='2176' tid='2175', class="m">==</a> <a id='2178' tid='2177', class="m">is_histogram</a>);
  }
  <a id='2180' tid='2179', class="m">return</a> <a id='2182' tid='2181', class="m">counter</a>;
}


<a id='2044' tid='2043', class="m">int</a><a id='2046' tid='2045', class="m">*</a> <a id='2048' tid='2047', class="m">Shell</a><a id='2050' tid='2049', class="m">::</a><a id='2052' tid='2051', class="m">LookupCounter</a>(<a id='2054' tid='2053', class="m">const</a> <a id='2056' tid='2055', class="m">char</a><a id='2058' tid='2057', class="m">*</a> <a id='2060' tid='2059', class="m">name</a>) {
  <a id='2062' tid='2061', class="m">Counter</a><a id='2064' tid='2063', class="m">*</a> <a id='2066' tid='2065', class="m">counter</a> = <a id='2068' tid='2067', class="m">GetCounter</a>(<a id='2070' tid='2069', class="m">name</a>, <a id='2072' tid='2071', class="m">false</a>);

  <a id='2074' tid='2073', class="m">if</a> (<a id='2076' tid='2075', class="m">counter</a> <a id='2078' tid='2077', class="m">!=</a> <a id='2080' tid='2079', class="m">NULL</a>) {
    <a id='2082' tid='2081', class="m">return</a> <a id='2084' tid='2083', class="m">counter</a>-&gt;<a id='2086' tid='2085', class="m">ptr</a>();
  } <a id='2088' tid='2087', class="m">else</a> {
    <a id='2090' tid='2089', class="m">return</a> <a id='2092' tid='2091', class="m">NULL</a>;
  }
}


<a id='2006' tid='2005', class="m">void</a><a id='2008' tid='2007', class="m">*</a> <a id='2010' tid='2009', class="m">Shell</a><a id='2012' tid='2011', class="m">::</a><a id='2014' tid='2013', class="m">CreateHistogram</a>(<a id='2016' tid='2015', class="m">const</a> <a id='2018' tid='2017', class="m">char</a><a id='2020' tid='2019', class="m">*</a> <a id='2022' tid='2021', class="m">name</a>,
                             <a id='2024' tid='2023', class="m">int</a> <a id='2026' tid='2025', class="m">min</a>,
                             <a id='2028' tid='2027', class="m">int</a> <a id='2030' tid='2029', class="m">max</a>,
                             <a id='2032' tid='2031', class="m">size_t</a> <a id='2034' tid='2033', class="m">buckets</a>) {
  <a id='2036' tid='2035', class="m">return</a> <a id='2038' tid='2037', class="m">GetCounter</a>(<a id='2040' tid='2039', class="m">name</a>, <a id='2042' tid='2041', class="m">true</a>);
}


<a id='1968' tid='1967', class="m">void</a> <a id='1970' tid='1969', class="m">Shell</a><a id='1972' tid='1971', class="m">::</a><a id='1974' tid='1973', class="m">AddHistogramSample</a>(<a id='1976' tid='1975', class="m">void</a><a id='1978' tid='1977', class="m">*</a> <a id='1980' tid='1979', class="m">histogram</a>, <a id='1982' tid='1981', class="m">int</a> <a id='1984' tid='1983', class="m">sample</a>) {
  <a id='1986' tid='1985', class="m">Counter</a><a id='1988' tid='1987', class="m">*</a> <a id='1990' tid='1989', class="m">counter</a> = <a id='1992' tid='1991', class="m">reinterpret_cast</a>&lt;<a id='1994' tid='1993', class="m">Counter</a><a id='1996' tid='1995', class="m">*</a>&gt;(<a id='1998' tid='1997', class="m">histogram</a>);
  <a id='2000' tid='1999', class="m">counter</a>-&gt;<a id='2002' tid='2001', class="m">AddSample</a>(<a id='2004' tid='2003', class="m">sample</a>);
}

<span class="i">void</span> <span class="i">Shell::InstallUtilityScript</span><span class="i">()</span> {
  <span class="i">Locker lock;</span>
  <span class="i">HandleScope scope;</span>
  // If we use the utility context, we have to set the security tokens so that
  // utility, evaluation and debug context can all access each other.
  <span class="i">utility_context_-&gt;SetSecurityToken(Undefined());</span>
  <span class="i">evaluation_context_-&gt;SetSecurityToken(Undefined());</span>
  <a id='1958' tid='1957', class="m">Context</a><a id='1960' tid='1959', class="m">::</a><a id='1962' tid='1961', class="m">Scope</a> <a id='1964' tid='1963', class="m">utility_scope</a>(<a id='1966' tid='1965', class="m">utility_context_</a>);

<span class="i">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
  // Install the debugger object in the utility scope
  <span class="i">i::Debug* debug = i::Isolate::Current()-&gt;debug();</span>
  <span class="i">debug-&gt;Load();</span>
  <span class="i">i::Handle&lt;i::JSObject&gt; js_debug
      = i::Handle&lt;i::JSObject&gt;(debug-&gt;debug_context()-&gt;global());</span>
  <span class="i">utility_context_-&gt;Global()-&gt;Set(String::New(&quot;$debug&quot;),
                                  Utils::ToLocal(js_debug));</span>
  <span class="i">debug-&gt;debug_context()-&gt;set_security_token(HEAP-&gt;undefined_value());</span>
<span class="i">#endif</span>

  // Run the d8 shell utility script in the utility context
  <a id='1936' tid='1935', class="m">int</a> <a id='1938' tid='1937', class="m">source_index</a> = <a id='1940' tid='1939', class="m">i</a><a id='1942' tid='1941', class="m">::</a><a id='1944' tid='1943', class="m">NativesCollection</a>&lt;<a id='1946' tid='1945', class="m">i</a><a id='1948' tid='1947', class="m">::</a><a id='1950' tid='1949', class="m">D8</a>&gt;<a id='1952' tid='1951', class="m">::</a><a id='1954' tid='1953', class="m">GetIndex</a>(<a id='1956' tid='1955', class="m">&quot;d8&quot;</a>);
  <a id='1578' tid='1577', class="m">i</a><a id='1580' tid='1579', class="m">::</a><a id='1582' tid='1581', class="m">Vector</a>&lt;<a id='1584' tid='1583', class="m">const</a> <a id='1586' tid='1585', class="m">char</a>&gt; <span class="i">shell_source =
      i::NativesCollection&lt;i::D8&gt;::GetRawScriptSource(source_index)</span>;
  <a id='1440' tid='1439', class="m">i</a><a id='1442' tid='1441', class="m">::</a><a id='1444' tid='1443', class="m">Vector</a>&lt;<a id='1446' tid='1445', class="m">const</a> <a id='1448' tid='1447', class="m">char</a>&gt; <a id='1450' tid='1449', class="m">shell_source_name</a> =
      <a id='1452' tid='1451', class="m">i</a><a id='1454' tid='1453', class="m">::</a><a id='1456' tid='1455', class="m">NativesCollection</a>&lt;<a id='1458' tid='1457', class="m">i</a><a id='1460' tid='1459', class="m">::</a><a id='1462' tid='1461', class="m">D8</a>&gt;<a id='1464' tid='1463', class="m">::</a><a id='1466' tid='1465', class="m">GetScriptName</a>(<a id='1468' tid='1467', class="m">source_index</a>);
  <a id='1250' tid='1249', class="m">Handle</a>&lt;<a id='1252' tid='1251', class="m">String</a>&gt; <a id='1254' tid='1253', class="m">source</a> = <a id='1256' tid='1255', class="m">String</a><a id='1258' tid='1257', class="m">::</a><a id='1260' tid='1259', class="m">New</a>(<a id='1262' tid='1261', class="m">shell_source</a>.<a id='1264' tid='1263', class="m">start</a>(),
      <a id='1266' tid='1265', class="m">shell_source</a>.<a id='1268' tid='1267', class="m">length</a>());
  <a id='556' tid='555', class="m">Handle</a>&lt;<a id='558' tid='557', class="m">String</a>&gt; <a id='560' tid='559', class="m">name</a> = <a id='562' tid='561', class="m">String</a><a id='564' tid='563', class="m">::</a><a id='566' tid='565', class="m">New</a>(<a id='568' tid='567', class="m">shell_source_name</a>.<a id='570' tid='569', class="m">start</a>(),
      <a id='572' tid='571', class="m">shell_source_name</a>.<a id='574' tid='573', class="m">length</a>());
  <a id='314' tid='313', class="m">Handle</a>&lt;<a id='316' tid='315', class="m">Script</a>&gt; <a id='318' tid='317', class="m">script</a> = <a id='320' tid='319', class="m">Script</a><a id='322' tid='321', class="m">::</a><a id='324' tid='323', class="m">Compile</a>(<a id='326' tid='325', class="m">source</a>, <a id='328' tid='327', class="m">name</a>);
  <span class="i">script-&gt;Run();</span>

  // Mark the d8 shell script as native to avoid it showing up as normal source
  // in the debugger.
  <span class="i">i::Handle&lt;i::Object&gt;</span> <span class="i">compiled_script</span> = <a id='286' tid='285', class="m">Utils</a><a id='288' tid='287', class="m">::</a><a id='290' tid='289', class="m">OpenHandle</a>(<a id='292' tid='291', class="m">*</a><a id='294' tid='293', class="m">script</a>);
  <a id='214' tid='213', class="m">i</a><a id='216' tid='215', class="m">::</a><a id='218' tid='217', class="m">Handle</a>&lt;<a id='220' tid='219', class="m">i</a><a id='222' tid='221', class="m">::</a><a id='224' tid='223', class="m">Script</a>&gt; <a id='226' tid='225', class="m">script_object</a> = <span class="i">compiled_script-&gt;IsJSFunction()</span>
     ? <a id='228' tid='227', class="m">i</a><a id='230' tid='229', class="m">::</a><a id='232' tid='231', class="m">Handle</a>&lt;<a id='234' tid='233', class="m">i</a><a id='236' tid='235', class="m">::</a><a id='238' tid='237', class="m">Script</a>&gt;(<a id='240' tid='239', class="m">i</a><a id='242' tid='241', class="m">::</a><a id='244' tid='243', class="m">Script</a><a id='246' tid='245', class="m">::</a><a id='248' tid='247', class="m">cast</a><span class="i">(
         i::JSFunction::cast(*compiled_script)-&gt;shared()-&gt;script())</span>)
     : <span class="i">i::Handle&lt;i::Script&gt;(i::Script::cast(
         i::SharedFunctionInfo::cast(*compiled_script)-&gt;script()))</span>;
  <a id='114' tid='113', class="m">script_object</a>-&gt;<a id='116' tid='115', class="m">set_type</a>(<a id='118' tid='117', class="m">i</a><a id='120' tid='119', class="m">::</a><a id='122' tid='121', class="m">Smi</a><a id='124' tid='123', class="m">::</a><a id='126' tid='125', class="m">FromInt</a>(<a id='128' tid='127', class="m">i</a><a id='130' tid='129', class="m">::</a><a id='132' tid='131', class="m">Script</a><a id='134' tid='133', class="m">::</a><a id='136' tid='135', class="m">TYPE_NATIVE</a>));
}


<span class="i">#ifdef COMPRESS_STARTUP_DATA_BZ2</span>
<span class="i">class BZip2Decompressor : public v8::StartupDataDecompressor {
 public:
  virtual ~BZip2Decompressor() { }

 protected:
  virtual int DecompressData(char* raw_data,
                             int* raw_data_size,
                             const char* compressed_data,
                             int compressed_data_size) {
    ASSERT_EQ(v8::StartupData::kBZip2,
              v8::V8::GetCompressedStartupDataAlgorithm());
    unsigned int decompressed_size = *raw_data_size;
    int result =
        BZ2_bzBuffToBuffDecompress(raw_data,
                                   &decompressed_size,
                                   const_cast&lt;char*&gt;(compressed_data),
                                   compressed_data_size,
                                   0, 1);
    if (result == BZ_OK) {
      *raw_data_size = decompressed_size;
    }
    return result;
  }
}</span>;
<span class="i">#endif</span>

<span class="i">Handle&lt;ObjectTemplate&gt;</span> <span class="i">Shell::CreateGlobalTemplate</span><span class="i">()</span> {
  <a id='1924' tid='1923', class="m">Handle</a>&lt;<a id='1926' tid='1925', class="m">ObjectTemplate</a>&gt; <a id='1928' tid='1927', class="m">global_template</a> = <a id='1930' tid='1929', class="m">ObjectTemplate</a><a id='1932' tid='1931', class="m">::</a><a id='1934' tid='1933', class="m">New</a>();
  <a id='1904' tid='1903', class="m">global_template</a>-&gt;<a id='1906' tid='1905', class="m">Set</a>(<a id='1908' tid='1907', class="m">String</a><a id='1910' tid='1909', class="m">::</a><a id='1912' tid='1911', class="m">New</a>(<a id='1914' tid='1913', class="m">&quot;print&quot;</a>), <a id='1916' tid='1915', class="m">FunctionTemplate</a><a id='1918' tid='1917', class="m">::</a><a id='1920' tid='1919', class="m">New</a>(<a id='1922' tid='1921', class="m">Print</a>));
  <a id='1752' tid='1751', class="m">global_template</a>-&gt;<a id='1754' tid='1753', class="m">Set</a>(<a id='1756' tid='1755', class="m">String</a><a id='1758' tid='1757', class="m">::</a><a id='1760' tid='1759', class="m">New</a>(<a id='1762' tid='1761', class="m">&quot;write&quot;</a>), <a id='1764' tid='1763', class="m">FunctionTemplate</a><a id='1766' tid='1765', class="m">::</a><a id='1768' tid='1767', class="m">New</a>(<a id='1770' tid='1769', class="m">Write</a>));
  <a id='1492' tid='1491', class="m">global_template</a>-&gt;<a id='1494' tid='1493', class="m">Set</a>(<a id='1496' tid='1495', class="m">String</a><a id='1498' tid='1497', class="m">::</a><a id='1500' tid='1499', class="m">New</a>(<a id='1502' tid='1501', class="m">&quot;read&quot;</a>), <a id='1504' tid='1503', class="m">FunctionTemplate</a><a id='1506' tid='1505', class="m">::</a><a id='1508' tid='1507', class="m">New</a>(<a id='1510' tid='1509', class="m">Read</a>));
  <a id='1398' tid='1397', class="m">global_template</a>-&gt;<a id='1400' tid='1399', class="m">Set</a>(<a id='1402' tid='1401', class="m">String</a><a id='1404' tid='1403', class="m">::</a><a id='1406' tid='1405', class="m">New</a>(<a id='1408' tid='1407', class="m">&quot;readline&quot;</a>),
                       <a id='1410' tid='1409', class="m">FunctionTemplate</a><a id='1412' tid='1411', class="m">::</a><a id='1414' tid='1413', class="m">New</a>(<a id='1416' tid='1415', class="m">ReadLine</a>));
  <a id='1304' tid='1303', class="m">global_template</a>-&gt;<a id='1306' tid='1305', class="m">Set</a>(<a id='1308' tid='1307', class="m">String</a><a id='1310' tid='1309', class="m">::</a><a id='1312' tid='1311', class="m">New</a>(<a id='1314' tid='1313', class="m">&quot;load&quot;</a>), <a id='1316' tid='1315', class="m">FunctionTemplate</a><a id='1318' tid='1317', class="m">::</a><a id='1320' tid='1319', class="m">New</a>(<a id='1322' tid='1321', class="m">Load</a>));
  <a id='1086' tid='1085', class="m">global_template</a>-&gt;<a id='1088' tid='1087', class="m">Set</a>(<a id='1090' tid='1089', class="m">String</a><a id='1092' tid='1091', class="m">::</a><a id='1094' tid='1093', class="m">New</a>(<a id='1096' tid='1095', class="m">&quot;quit&quot;</a>), <a id='1098' tid='1097', class="m">FunctionTemplate</a><a id='1100' tid='1099', class="m">::</a><a id='1102' tid='1101', class="m">New</a>(<a id='1104' tid='1103', class="m">Quit</a>));
  <a id='438' tid='437', class="m">global_template</a>-&gt;<a id='440' tid='439', class="m">Set</a>(<a id='442' tid='441', class="m">String</a><a id='444' tid='443', class="m">::</a><a id='446' tid='445', class="m">New</a>(<a id='448' tid='447', class="m">&quot;version&quot;</a>), <a id='450' tid='449', class="m">FunctionTemplate</a><a id='452' tid='451', class="m">::</a><a id='454' tid='453', class="m">New</a>(<a id='456' tid='455', class="m">Version</a>));

  // Bind the handlers for external arrays.
  <span class="i">global_template-&gt;Set(String::New(&quot;Int8Array&quot;),
                       FunctionTemplate::New(Int8Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Uint8Array&quot;),
                       FunctionTemplate::New(Uint8Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Int16Array&quot;),
                       FunctionTemplate::New(Int16Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Uint16Array&quot;),
                       FunctionTemplate::New(Uint16Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Int32Array&quot;),
                       FunctionTemplate::New(Int32Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Uint32Array&quot;),
                       FunctionTemplate::New(Uint32Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Float32Array&quot;),
                       FunctionTemplate::New(Float32Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;Float64Array&quot;),
                       FunctionTemplate::New(Float64Array));</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;PixelArray&quot;),
                       FunctionTemplate::New(PixelArray));</span>

<span class="i">#ifdef LIVE_OBJECT_LIST</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;lol_is_enabled&quot;), Boolean::New(true));</span>
<span class="i">#else</span>
  <span class="i">global_template-&gt;Set(String::New(&quot;lol_is_enabled&quot;), Boolean::New(false));</span>
<span class="i">#endif</span>

  <a id='264' tid='263', class="m">Handle</a>&lt;<a id='266' tid='265', class="m">ObjectTemplate</a>&gt; <a id='268' tid='267', class="m">os_templ</a> = <a id='270' tid='269', class="m">ObjectTemplate</a><a id='272' tid='271', class="m">::</a><a id='274' tid='273', class="m">New</a>();
  <span class="i">AddOSMethods(os_templ);</span>
  <a id='250' tid='249', class="m">global_template</a>-&gt;<a id='252' tid='251', class="m">Set</a>(<a id='254' tid='253', class="m">String</a><a id='256' tid='255', class="m">::</a><a id='258' tid='257', class="m">New</a>(<a id='260' tid='259', class="m">&quot;os&quot;</a>), <a id='262' tid='261', class="m">os_templ</a>);

  <span class="i">return global_template;</span>
}


<span class="i">void</span> <span class="i">Shell::Initialize</span><span class="i">(bool test_shell)</span> {
<span class="i">#ifdef COMPRESS_STARTUP_DATA_BZ2</span>
  <span class="i">BZip2Decompressor startup_data_decompressor;</span>
  <span class="i">int bz2_result = startup_data_decompressor.Decompress();</span>
  <span class="i">if (bz2_result != BZ_OK) {
    fprintf(stderr, &quot;bzip error code: %d\n&quot;, bz2_result);
    exit(1);
  }</span>
<span class="i">#endif</span>

  <a id='1044' tid='1043', class="m">Shell</a><a id='1046' tid='1045', class="m">::</a><a id='1048' tid='1047', class="m">counter_map_</a> <a id='1050' tid='1049', class="m">=</a> <a id='1052' tid='1051', class="m">new</a> <a id='1054' tid='1053', class="m">CounterMap</a>();
  // Set up counters
  <span class="i">if (i::StrLength(i::FLAG_map_counters) != 0)
    MapCounters(i::FLAG_map_counters);</span>
  <a id='182' tid='181', class="m">if</a> (<a id='184' tid='183', class="m">i</a><a id='186' tid='185', class="m">::</a><a id='188' tid='187', class="m">FLAG_dump_counters</a>) {
    <a id='190' tid='189', class="m">V8</a><a id='192' tid='191', class="m">::</a><a id='194' tid='193', class="m">SetCounterFunction</a>(<a id='196' tid='195', class="m">LookupCounter</a>);
    <a id='198' tid='197', class="m">V8</a><a id='200' tid='199', class="m">::</a><a id='202' tid='201', class="m">SetCreateHistogramFunction</a>(<a id='204' tid='203', class="m">CreateHistogram</a>);
    <a id='206' tid='205', class="m">V8</a><a id='208' tid='207', class="m">::</a><a id='210' tid='209', class="m">SetAddHistogramSampleFunction</a>(<a id='212' tid='211', class="m">AddHistogramSample</a>);
  }

  <span class="i">if (test_shell) return;</span>

  <span class="i">Locker lock;</span>
  <span class="i">HandleScope scope;</span>
  <span class="i">Handle&lt;ObjectTemplate&gt; global_template = CreateGlobalTemplate();</span>
  <span class="i">utility_context_ = Context::New(NULL, global_template);</span>

<span class="i">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
  // Start the debugger agent if requested.
  <a id='150' tid='149', class="m">if</a> (<a id='152' tid='151', class="m">i</a><a id='154' tid='153', class="m">::</a><a id='156' tid='155', class="m">FLAG_debugger_agent</a>) {
    <a id='158' tid='157', class="m">v8</a><a id='160' tid='159', class="m">::</a><a id='162' tid='161', class="m">Debug</a><a id='164' tid='163', class="m">::</a><a id='166' tid='165', class="m">EnableAgent</a><span class="i">(&quot;d8 shell&quot;, i::FLAG_debugger_port, true)</span>;
  }

  // Start the in-process debugger if requested.
  <a id='84' tid='83', class="m">if</a> (<a id='86' tid='85', class="m">i</a><a id='88' tid='87', class="m">::</a><a id='90' tid='89', class="m">FLAG_debugger</a> <a id='92' tid='91', class="m">&&</a> <a id='94' tid='93', class="m">!</a><a id='96' tid='95', class="m">i</a><a id='98' tid='97', class="m">::</a><a id='100' tid='99', class="m">FLAG_debugger_agent</a>) {
    <a id='102' tid='101', class="m">v8</a><a id='104' tid='103', class="m">::</a><a id='106' tid='105', class="m">Debug</a><a id='108' tid='107', class="m">::</a><a id='110' tid='109', class="m">SetDebugEventListener</a>(<a id='112' tid='111', class="m">HandleDebugEvent</a>);
  }
<span class="i">#endif</span>
}


<span class="i">void</span> <span class="i">Shell::RenewEvaluationContext</span><span class="i">()</span> {
  // Initialize the global objects
  <span class="i">HandleScope scope;</span>
  <span class="i">Handle&lt;ObjectTemplate&gt; global_template = CreateGlobalTemplate();</span>

  // (Re-)create the evaluation context
  <span class="i">if (!evaluation_context_.IsEmpty()) {
    evaluation_context_.Dispose();
  }</span>
  <span class="i">evaluation_context_</span> <span class="i">=</span> <a id='954' tid='953', class="m">Context</a><a id='956' tid='955', class="m">::</a><a id='958' tid='957', class="m">New</a>(<a id='960' tid='959', class="m">NULL</a>, <a id='962' tid='961', class="m">global_template</a>);
  <span class="i">Context::Scope utility_scope(evaluation_context_)</span>;

  <a id='168' tid='167', class="m">i</a><a id='170' tid='169', class="m">::</a><a id='172' tid='171', class="m">JSArguments</a> <a id='174' tid='173', class="m">js_args</a> = <a id='176' tid='175', class="m">i</a><a id='178' tid='177', class="m">::</a><a id='180' tid='179', class="m">FLAG_js_arguments</a>;
  <a id='138' tid='137', class="m">i</a><a id='140' tid='139', class="m">::</a><a id='142' tid='141', class="m">Handle</a>&lt;<a id='144' tid='143', class="m">i</a><a id='146' tid='145', class="m">::</a><a id='148' tid='147', class="m">FixedArray</a>&gt; <span class="i">arguments_array =
      FACTORY-&gt;NewFixedArray(js_args.argc())</span>;
  <a id='30' tid='29', class="m">for</a> (<a id='32' tid='31', class="m">int</a> <a id='34' tid='33', class="m">j</a> = <a id='36' tid='35', class="m">0</a>; <a id='38' tid='37', class="m">j</a> <a id='40' tid='39', class="m">&lt;</a> <a id='42' tid='41', class="m">js_args</a>.<a id='44' tid='43', class="m">argc</a>(); <a id='46' tid='45', class="m">j</a><a id='48' tid='47', class="m">++</a>) {
    <a id='50' tid='49', class="m">i</a><a id='52' tid='51', class="m">::</a><a id='54' tid='53', class="m">Handle</a>&lt;<a id='56' tid='55', class="m">i</a><a id='58' tid='57', class="m">::</a><a id='60' tid='59', class="m">String</a>&gt; <a id='62' tid='61', class="m">arg</a> =
        <span class="i">FACTORY-&gt;NewStringFromUtf8</span>(<a id='64' tid='63', class="m">i</a><a id='66' tid='65', class="m">::</a><a id='68' tid='67', class="m">CStrVector</a>(<a id='70' tid='69', class="m">js_args</a>[<a id='72' tid='71', class="m">j</a>]));
    <a id='74' tid='73', class="m">arguments_array</a>-&gt;<a id='76' tid='75', class="m">set</a>(<a id='78' tid='77', class="m">j</a>, <a id='80' tid='79', class="m">*</a><a id='82' tid='81', class="m">arg</a>);
  }
  <a id='18' tid='17', class="m">i</a><a id='20' tid='19', class="m">::</a><a id='22' tid='21', class="m">Handle</a>&lt;<a id='24' tid='23', class="m">i</a><a id='26' tid='25', class="m">::</a><a id='28' tid='27', class="m">JSArray</a>&gt; <span class="i">arguments_jsarray =
      FACTORY-&gt;NewJSArrayWithElements(arguments_array)</span>;
  <span class="i">evaluation_context_-&gt;Global()-&gt;Set</span>(<a id='2' tid='1', class="m">String</a><a id='4' tid='3', class="m">::</a><a id='6' tid='5', class="m">New</a>(<a id='8' tid='7', class="m">&quot;arguments&quot;</a>),
                                     <a id='10' tid='9', class="m">Utils</a><a id='12' tid='11', class="m">::</a><a id='14' tid='13', class="m">ToLocal</a>(<a id='16' tid='15', class="m">arguments_jsarray</a>));
}


<a id='1772' tid='1771', class="m">void</a> <a id='1774' tid='1773', class="m">Shell</a><a id='1776' tid='1775', class="m">::</a><a id='1778' tid='1777', class="m">OnExit</a>() {
  <a id='1780' tid='1779', class="m">if</a> (<a id='1782' tid='1781', class="m">i</a><a id='1784' tid='1783', class="m">::</a><a id='1786' tid='1785', class="m">FLAG_dump_counters</a>) {
    <a id='1788' tid='1787', class="m">::</a><a id='1790' tid='1789', class="m">printf</a>(<a id='1792' tid='1791', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
    <a id='1794' tid='1793', class="m">::</a><a id='1796' tid='1795', class="m">printf</a>(<a id='1798' tid='1797', class="m">&quot;| Name                                   | Value       |\n&quot;</a>);
    <a id='1800' tid='1799', class="m">::</a><a id='1802' tid='1801', class="m">printf</a>(<a id='1804' tid='1803', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
    <a id='1806' tid='1805', class="m">for</a> (<a id='1808' tid='1807', class="m">CounterMap</a><a id='1810' tid='1809', class="m">::</a><a id='1812' tid='1811', class="m">Iterator</a> <a id='1814' tid='1813', class="m">i</a>(<a id='1816' tid='1815', class="m">counter_map_</a>); <a id='1818' tid='1817', class="m">i</a>.<a id='1820' tid='1819', class="m">More</a>(); <a id='1822' tid='1821', class="m">i</a>.<a id='1824' tid='1823', class="m">Next</a>()) {
      <a id='1826' tid='1825', class="m">Counter</a><a id='1828' tid='1827', class="m">*</a> <a id='1830' tid='1829', class="m">counter</a> = <a id='1832' tid='1831', class="m">i</a>.<a id='1834' tid='1833', class="m">CurrentValue</a>();
      <a id='1836' tid='1835', class="m">if</a> (<a id='1838' tid='1837', class="m">counter</a>-&gt;<a id='1840' tid='1839', class="m">is_histogram</a>()) {
        <a id='1842' tid='1841', class="m">::</a><a id='1844' tid='1843', class="m">printf</a>(<a id='1846' tid='1845', class="m">&quot;| c:%-36s | %11i |\n&quot;</a>, <a id='1848' tid='1847', class="m">i</a>.<a id='1850' tid='1849', class="m">CurrentKey</a>(), <a id='1852' tid='1851', class="m">counter</a>-&gt;<a id='1854' tid='1853', class="m">count</a>());
        <a id='1856' tid='1855', class="m">::</a><a id='1858' tid='1857', class="m">printf</a>(<a id='1860' tid='1859', class="m">&quot;| t:%-36s | %11i |\n&quot;</a>,
                 <a id='1862' tid='1861', class="m">i</a>.<a id='1864' tid='1863', class="m">CurrentKey</a>(),
                 <a id='1866' tid='1865', class="m">counter</a>-&gt;<a id='1868' tid='1867', class="m">sample_total</a>());
      } <a id='1870' tid='1869', class="m">else</a> {
        <a id='1872' tid='1871', class="m">::</a><a id='1874' tid='1873', class="m">printf</a>(<a id='1876' tid='1875', class="m">&quot;| %-38s | %11i |\n&quot;</a>, <a id='1878' tid='1877', class="m">i</a>.<a id='1880' tid='1879', class="m">CurrentKey</a>(), <a id='1882' tid='1881', class="m">counter</a>-&gt;<a id='1884' tid='1883', class="m">count</a>());
      }
    }
    <a id='1886' tid='1885', class="m">::</a><a id='1888' tid='1887', class="m">printf</a>(<a id='1890' tid='1889', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
  }
  <a id='1892' tid='1891', class="m">if</a> (<a id='1894' tid='1893', class="m">counters_file_</a> <a id='1896' tid='1895', class="m">!=</a> <a id='1898' tid='1897', class="m">NULL</a>)
    <a id='1900' tid='1899', class="m">delete</a> <a id='1902' tid='1901', class="m">counters_file_</a>;
}


<a id='1588' tid='1587', class="m">static</a> <a id='1590' tid='1589', class="m">char</a><a id='1592' tid='1591', class="m">*</a> <a id='1594' tid='1593', class="m">ReadChars</a>(<a id='1596' tid='1595', class="m">const</a> <a id='1598' tid='1597', class="m">char</a><a id='1600' tid='1599', class="m">*</a> <a id='1602' tid='1601', class="m">name</a>, <a id='1604' tid='1603', class="m">int</a><a id='1606' tid='1605', class="m">*</a> <a id='1608' tid='1607', class="m">size_out</a>) {
  <a id='1610' tid='1609', class="m">v8</a><a id='1612' tid='1611', class="m">::</a><a id='1614' tid='1613', class="m">Unlocker</a> <a id='1616' tid='1615', class="m">unlocker</a>;  // Release the V8 lock while reading files.
  <a id='1618' tid='1617', class="m">FILE</a><a id='1620' tid='1619', class="m">*</a> <a id='1622' tid='1621', class="m">file</a> = <a id='1624' tid='1623', class="m">i</a><a id='1626' tid='1625', class="m">::</a><a id='1628' tid='1627', class="m">OS</a><a id='1630' tid='1629', class="m">::</a><a id='1632' tid='1631', class="m">FOpen</a>(<a id='1634' tid='1633', class="m">name</a>, <a id='1636' tid='1635', class="m">&quot;rb&quot;</a>);
  <a id='1638' tid='1637', class="m">if</a> (<a id='1640' tid='1639', class="m">file</a> <a id='1642' tid='1641', class="m">==</a> <a id='1644' tid='1643', class="m">NULL</a>) <a id='1646' tid='1645', class="m">return</a> <a id='1648' tid='1647', class="m">NULL</a>;

  <a id='1650' tid='1649', class="m">fseek</a>(<a id='1652' tid='1651', class="m">file</a>, <a id='1654' tid='1653', class="m">0</a>, <a id='1656' tid='1655', class="m">SEEK_END</a>);
  <a id='1658' tid='1657', class="m">int</a> <a id='1660' tid='1659', class="m">size</a> = <a id='1662' tid='1661', class="m">ftell</a>(<a id='1664' tid='1663', class="m">file</a>);
  <a id='1666' tid='1665', class="m">rewind</a>(<a id='1668' tid='1667', class="m">file</a>);

  <a id='1670' tid='1669', class="m">char</a><a id='1672' tid='1671', class="m">*</a> <a id='1674' tid='1673', class="m">chars</a> = <a id='1676' tid='1675', class="m">new</a> <a id='1678' tid='1677', class="m">char</a>[<a id='1680' tid='1679', class="m">size</a> <a id='1682' tid='1681', class="m">+</a> <a id='1684' tid='1683', class="m">1</a>];
  <a id='1686' tid='1685', class="m">chars</a>[<a id='1688' tid='1687', class="m">size</a>] <a id='1690' tid='1689', class="m">=</a> <a id='1692' tid='1691', class="m">&#39;\0&#39;</a>;
  <a id='1694' tid='1693', class="m">for</a> (<a id='1696' tid='1695', class="m">int</a> <a id='1698' tid='1697', class="m">i</a> = <a id='1700' tid='1699', class="m">0</a>; <a id='1702' tid='1701', class="m">i</a> <a id='1704' tid='1703', class="m">&lt;</a> <a id='1706' tid='1705', class="m">size</a>;) {
    <a id='1708' tid='1707', class="m">int</a> <a id='1710' tid='1709', class="m">read</a> = <a id='1712' tid='1711', class="m">fread</a>(<a id='1714' tid='1713', class="m">&</a><a id='1716' tid='1715', class="m">chars</a>[<a id='1718' tid='1717', class="m">i</a>], <a id='1720' tid='1719', class="m">1</a>, <a id='1722' tid='1721', class="m">size</a> <a id='1724' tid='1723', class="m">-</a> <a id='1726' tid='1725', class="m">i</a>, <a id='1728' tid='1727', class="m">file</a>);
    <a id='1730' tid='1729', class="m">i</a> <a id='1732' tid='1731', class="m">+=</a> <a id='1734' tid='1733', class="m">read</a>;
  }
  <a id='1736' tid='1735', class="m">fclose</a>(<a id='1738' tid='1737', class="m">file</a>);
  <a id='1740' tid='1739', class="m">*</a><a id='1742' tid='1741', class="m">size_out</a> <a id='1744' tid='1743', class="m">=</a> <a id='1746' tid='1745', class="m">size</a>;
  <a id='1748' tid='1747', class="m">return</a> <a id='1750' tid='1749', class="m">chars</a>;
}


<a id='1512' tid='1511', class="m">static</a> <a id='1514' tid='1513', class="m">char</a><a id='1516' tid='1515', class="m">*</a> <a id='1518' tid='1517', class="m">ReadToken</a>(<a id='1520' tid='1519', class="m">char</a><a id='1522' tid='1521', class="m">*</a> <a id='1524' tid='1523', class="m">data</a>, <a id='1526' tid='1525', class="m">char</a> <a id='1528' tid='1527', class="m">token</a>) {
  <a id='1530' tid='1529', class="m">char</a><a id='1532' tid='1531', class="m">*</a> <a id='1534' tid='1533', class="m">next</a> = <a id='1536' tid='1535', class="m">i</a><a id='1538' tid='1537', class="m">::</a><a id='1540' tid='1539', class="m">OS</a><a id='1542' tid='1541', class="m">::</a><a id='1544' tid='1543', class="m">StrChr</a>(<a id='1546' tid='1545', class="m">data</a>, <a id='1548' tid='1547', class="m">token</a>);
  <a id='1550' tid='1549', class="m">if</a> (<a id='1552' tid='1551', class="m">next</a> <a id='1554' tid='1553', class="m">!=</a> <a id='1556' tid='1555', class="m">NULL</a>) {
    <a id='1558' tid='1557', class="m">*</a><a id='1560' tid='1559', class="m">next</a> <a id='1562' tid='1561', class="m">=</a> <a id='1564' tid='1563', class="m">&#39;\0&#39;</a>;
    <a id='1566' tid='1565', class="m">return</a> (<a id='1568' tid='1567', class="m">next</a> <a id='1570' tid='1569', class="m">+</a> <a id='1572' tid='1571', class="m">1</a>);
  }

  <a id='1574' tid='1573', class="m">return</a> <a id='1576' tid='1575', class="m">NULL</a>;
}


<a id='1470' tid='1469', class="m">static</a> <a id='1472' tid='1471', class="m">char</a><a id='1474' tid='1473', class="m">*</a> <a id='1476' tid='1475', class="m">ReadLine</a>(<a id='1478' tid='1477', class="m">char</a><a id='1480' tid='1479', class="m">*</a> <a id='1482' tid='1481', class="m">data</a>) {
  <a id='1484' tid='1483', class="m">return</a> <a id='1486' tid='1485', class="m">ReadToken</a>(<a id='1488' tid='1487', class="m">data</a>, <a id='1490' tid='1489', class="m">&#39;\n&#39;</a>);
}


<a id='1418' tid='1417', class="m">static</a> <a id='1420' tid='1419', class="m">char</a><a id='1422' tid='1421', class="m">*</a> <a id='1424' tid='1423', class="m">ReadWord</a>(<a id='1426' tid='1425', class="m">char</a><a id='1428' tid='1427', class="m">*</a> <a id='1430' tid='1429', class="m">data</a>) {
  <a id='1432' tid='1431', class="m">return</a> <a id='1434' tid='1433', class="m">ReadToken</a>(<a id='1436' tid='1435', class="m">data</a>, <a id='1438' tid='1437', class="m">&#39; &#39;</a>);
}


// Reads a file into a v8 string.
<a id='1324' tid='1323', class="m">Handle</a>&lt;<a id='1326' tid='1325', class="m">String</a>&gt; <a id='1328' tid='1327', class="m">Shell</a><a id='1330' tid='1329', class="m">::</a><a id='1332' tid='1331', class="m">ReadFile</a>(<a id='1334' tid='1333', class="m">const</a> <a id='1336' tid='1335', class="m">char</a><a id='1338' tid='1337', class="m">*</a> <a id='1340' tid='1339', class="m">name</a>) {
  <a id='1342' tid='1341', class="m">int</a> <a id='1344' tid='1343', class="m">size</a> = <a id='1346' tid='1345', class="m">0</a>;
  <a id='1348' tid='1347', class="m">char</a><a id='1350' tid='1349', class="m">*</a> <a id='1352' tid='1351', class="m">chars</a> = <a id='1354' tid='1353', class="m">ReadChars</a>(<a id='1356' tid='1355', class="m">name</a>, <a id='1358' tid='1357', class="m">&</a><a id='1360' tid='1359', class="m">size</a>);
  <a id='1362' tid='1361', class="m">if</a> (<a id='1364' tid='1363', class="m">chars</a> <a id='1366' tid='1365', class="m">==</a> <a id='1368' tid='1367', class="m">NULL</a>) <a id='1370' tid='1369', class="m">return</a> <a id='1372' tid='1371', class="m">Handle</a>&lt;<a id='1374' tid='1373', class="m">String</a>&gt;();
  <a id='1376' tid='1375', class="m">Handle</a>&lt;<a id='1378' tid='1377', class="m">String</a>&gt; <a id='1380' tid='1379', class="m">result</a> = <a id='1382' tid='1381', class="m">String</a><a id='1384' tid='1383', class="m">::</a><a id='1386' tid='1385', class="m">New</a>(<a id='1388' tid='1387', class="m">chars</a>);
  <a id='1390' tid='1389', class="m">delete</a>[] <a id='1392' tid='1391', class="m">chars</a>;
  <a id='1394' tid='1393', class="m">return</a> <a id='1396' tid='1395', class="m">result</a>;
}


<a id='1284' tid='1283', class="m">void</a> <a id='1286' tid='1285', class="m">Shell</a><a id='1288' tid='1287', class="m">::</a><a id='1290' tid='1289', class="m">RunShell</a>() {
  <a id='1292' tid='1291', class="m">LineEditor</a><a id='1294' tid='1293', class="m">*</a> <a id='1296' tid='1295', class="m">editor</a> = <a id='1298' tid='1297', class="m">LineEditor</a><a id='1300' tid='1299', class="m">::</a><a id='1302' tid='1301', class="m">Get</a>();
  <a id='1270' tid='1269', class="m">printf</a>(<a id='1272' tid='1271', class="m">&quot;V8 version %s [console: %s]\n&quot;</a>, <a id='1274' tid='1273', class="m">V8</a><a id='1276' tid='1275', class="m">::</a><a id='1278' tid='1277', class="m">GetVersion</a>(), <a id='1280' tid='1279', class="m">editor</a>-&gt;<a id='1282' tid='1281', class="m">name</a>());
  <span class="i">if (i::FLAG_debugger) {
    printf(&quot;JavaScript debugger enabled\n&quot;);
  }</span>

  <span class="i">editor-&gt;Open();</span>
  <a id='1106' tid='1105', class="m">while</a> (<a id='1108' tid='1107', class="m">true</a>) {
    <a id='1120' tid='1119', class="m">Locker</a> <a id='1122' tid='1121', class="m">locker</a>;
    <a id='1124' tid='1123', class="m">HandleScope</a> <a id='1126' tid='1125', class="m">handle_scope</a>;
    <a id='1110' tid='1109', class="m">Context</a><a id='1112' tid='1111', class="m">::</a><a id='1114' tid='1113', class="m">Scope</a> <a id='1116' tid='1115', class="m">context_scope</a>(<a id='1118' tid='1117', class="m">evaluation_context_</a>);
    <a id='1128' tid='1127', class="m">i</a><a id='1130' tid='1129', class="m">::</a><a id='1132' tid='1131', class="m">SmartPointer</a>&lt;<a id='1134' tid='1133', class="m">char</a>&gt; <a id='1136' tid='1135', class="m">input</a> = <a id='1138' tid='1137', class="m">editor</a>-&gt;<a id='1140' tid='1139', class="m">Prompt</a>(<a id='1142' tid='1141', class="m">Shell</a><a id='1144' tid='1143', class="m">::</a><a id='1146' tid='1145', class="m">kPrompt</a>);
    <a id='1148' tid='1147', class="m">if</a> (<a id='1150' tid='1149', class="m">input</a>.<a id='1152' tid='1151', class="m">is_empty</a>())
      <a id='1154' tid='1153', class="m">break</a>;
    <a id='1156' tid='1155', class="m">editor</a>-&gt;<a id='1158' tid='1157', class="m">AddHistory</a>(<a id='1160' tid='1159', class="m">*</a><a id='1162' tid='1161', class="m">input</a>);
    <a id='1164' tid='1163', class="m">Handle</a>&lt;<a id='1166' tid='1165', class="m">String</a>&gt; <a id='1168' tid='1167', class="m">name</a> = <a id='1170' tid='1169', class="m">String</a><a id='1172' tid='1171', class="m">::</a><a id='1174' tid='1173', class="m">New</a>(<a id='1176' tid='1175', class="m">&quot;(d8)&quot;</a>);
    <a id='1178' tid='1177', class="m">ExecuteString</a>(<a id='1180' tid='1179', class="m">String</a><a id='1182' tid='1181', class="m">::</a><a id='1184' tid='1183', class="m">New</a>(<a id='1186' tid='1185', class="m">*</a><a id='1188' tid='1187', class="m">input</a>), <a id='1190' tid='1189', class="m">name</a>, <a id='1192' tid='1191', class="m">true</a>, <a id='1194' tid='1193', class="m">true</a>);
  }
  <span class="i">editor-&gt;Close();</span>
  <span class="i">printf(&quot;\n&quot;);</span>
}


<a id='1196' tid='1195', class="m">class</a> <a id='1198' tid='1197', class="m">ShellThread</a> : <a id='1200' tid='1199', class="m">public</a> <a id='1202' tid='1201', class="m">i</a><a id='1204' tid='1203', class="m">::</a><a id='1206' tid='1205', class="m">Thread</a> {
 <a id='1230' tid='1229', class="m">public</a>:
  <a id='1066' tid='1065', class="m">ShellThread</a>(<a id='1214' tid='1213', class="m">int</a> <a id='1216' tid='1215', class="m">no</a>, <a id='1218' tid='1217', class="m">i</a><a id='1220' tid='1219', class="m">::</a><a id='1222' tid='1221', class="m">Vector</a>&lt;<a id='1224' tid='1223', class="m">const</a> <a id='1226' tid='1225', class="m">char</a>&gt; <a id='1228' tid='1227', class="m">files</a>)
    : <span class="i">Thread(&quot;d8:ShellThread&quot;),
      no_(no), files_(files)</span> <span class="i">{ }</span>
  <a id='1208' tid='1207', class="m">virtual</a> <a id='1210' tid='1209', class="m">void</a> <a id='1212' tid='1211', class="m">Run</a>();
 <a id='1232' tid='1231', class="m">private</a>:
  <a id='1234' tid='1233', class="m">int</a> <a id='1236' tid='1235', class="m">no_</a>;
  <a id='1238' tid='1237', class="m">i</a><a id='1240' tid='1239', class="m">::</a><a id='1242' tid='1241', class="m">Vector</a>&lt;<a id='1244' tid='1243', class="m">const</a> <a id='1246' tid='1245', class="m">char</a>&gt; <a id='1248' tid='1247', class="m">files_</a>;
};


<span class="i">void</span> <span class="i">ShellThread::Run</span><span class="i">()</span> {
  // Prepare the context for this thread.
  <span class="i">Locker locker;</span>
  <span class="i">HandleScope scope;</span>
  <span class="i">Handle&lt;ObjectTemplate&gt; global_template = Shell::CreateGlobalTemplate();</span>

  <a id='458' tid='457', class="m">char</a><a id='460' tid='459', class="m">*</a> <a id='462' tid='461', class="m">ptr</a> = <a id='464' tid='463', class="m">const_cast</a>&lt;<a id='466' tid='465', class="m">char</a><a id='468' tid='467', class="m">*</a>&gt;(<a id='470' tid='469', class="m">files_</a>.<a id='472' tid='471', class="m">start</a>());
  <a id='474' tid='473', class="m">while</a> ((<a id='476' tid='475', class="m">ptr</a> <a id='478' tid='477', class="m">!=</a> <a id='480' tid='479', class="m">NULL</a>) <a id='482' tid='481', class="m">&&</a> (<a id='484' tid='483', class="m">*</a><a id='486' tid='485', class="m">ptr</a> <a id='488' tid='487', class="m">!=</a> <a id='490' tid='489', class="m">&#39;\0&#39;</a>)) {
    // For each newline-separated line.
    <a id='330' tid='329', class="m">char</a><a id='332' tid='331', class="m">*</a> <a id='334' tid='333', class="m">next_line</a> = <a id='336' tid='335', class="m">ReadLine</a>(<a id='338' tid='337', class="m">ptr</a>);

    <a id='296' tid='295', class="m">if</a> (<a id='298' tid='297', class="m">*</a><a id='300' tid='299', class="m">ptr</a> <a id='302' tid='301', class="m">==</a> <a id='304' tid='303', class="m">&#39;#&#39;</a>) {
      // Skip comment lines.
      <a id='306' tid='305', class="m">ptr</a> <a id='308' tid='307', class="m">=</a> <a id='310' tid='309', class="m">next_line</a>;
      <a id='312' tid='311', class="m">continue</a>;
    }

    <span class="i">Persistent&lt;Context&gt;</span> <span class="i">thread_context</span> = <a id='638' tid='637', class="m">Context</a><a id='640' tid='639', class="m">::</a><a id='642' tid='641', class="m">New</a>(<a id='644' tid='643', class="m">NULL</a>, <a id='646' tid='645', class="m">global_template</a>);
    <a id='276' tid='275', class="m">Context</a><a id='278' tid='277', class="m">::</a><a id='280' tid='279', class="m">Scope</a> <a id='282' tid='281', class="m">context_scope</a>(<a id='284' tid='283', class="m">thread_context</a>);

    <a id='340' tid='339', class="m">while</a> ((<a id='576' tid='575', class="m">ptr</a> <a id='578' tid='577', class="m">!=</a> <a id='580' tid='579', class="m">NULL</a>) <a id='582' tid='581', class="m">&&</a> (<a id='584' tid='583', class="m">*</a><a id='586' tid='585', class="m">ptr</a> <a id='588' tid='587', class="m">!=</a> <a id='590' tid='589', class="m">&#39;\0&#39;</a>)) {
      <a id='342' tid='341', class="m">char</a><a id='344' tid='343', class="m">*</a> <a id='346' tid='345', class="m">filename</a> = <a id='348' tid='347', class="m">ptr</a>;
      <a id='350' tid='349', class="m">ptr</a> <a id='352' tid='351', class="m">=</a> <a id='354' tid='353', class="m">ReadWord</a>(<a id='356' tid='355', class="m">ptr</a>);

      // Skip empty strings.
      <a id='358' tid='357', class="m">if</a> (<a id='360' tid='359', class="m">strlen</a>(<a id='362' tid='361', class="m">filename</a>) <a id='364' tid='363', class="m">==</a> <a id='366' tid='365', class="m">0</a>) {
        <a id='368' tid='367', class="m">break</a>;
      }

      <a id='370' tid='369', class="m">Handle</a>&lt;<a id='372' tid='371', class="m">String</a>&gt; <a id='374' tid='373', class="m">str</a> = <a id='376' tid='375', class="m">Shell</a><a id='378' tid='377', class="m">::</a><a id='380' tid='379', class="m">ReadFile</a>(<a id='382' tid='381', class="m">filename</a>);
      <a id='384' tid='383', class="m">if</a> (<a id='386' tid='385', class="m">str</a>.<a id='388' tid='387', class="m">IsEmpty</a>()) {
        <a id='390' tid='389', class="m">printf</a>(<a id='392' tid='391', class="m">&quot;WARNING: %s not found\n&quot;</a>, <a id='394' tid='393', class="m">filename</a>);
        <a id='396' tid='395', class="m">break</a>;
      }

      <a id='398' tid='397', class="m">Shell</a><a id='400' tid='399', class="m">::</a><a id='402' tid='401', class="m">ExecuteString</a>(<a id='404' tid='403', class="m">str</a>, <a id='406' tid='405', class="m">String</a><a id='408' tid='407', class="m">::</a><a id='410' tid='409', class="m">New</a>(<a id='412' tid='411', class="m">filename</a>), <a id='414' tid='413', class="m">false</a>, <a id='416' tid='415', class="m">false</a>);
    }

    <span class="i">thread_context.Dispose();</span>
    <span class="i">ptr = next_line;</span>
  }
}

<span class="i">int</span> <span class="i">Shell::RunMain</span><span class="i">(int argc, char* argv[], bool* executed)</span> {
  // Default use preemption if threads are created.
  <span class="i">bool use_preemption = true;</span>

  // Default to use lowest possible thread preemption interval to test as many
  // edgecases as possible.
  <span class="i">int preemption_interval = 1;</span>

  <a id='1068' tid='1067', class="m">i</a><a id='1070' tid='1069', class="m">::</a><a id='1072' tid='1071', class="m">List</a>&lt;<a id='1074' tid='1073', class="m">i</a><a id='1076' tid='1075', class="m">::</a><a id='1078' tid='1077', class="m">Thread</a><a id='1080' tid='1079', class="m">*</a>&gt; <a id='1082' tid='1081', class="m">threads</a>(<a id='1084' tid='1083', class="m">1</a>);

  {
    // Since the thread below may spawn new threads accessing V8 holding the
    // V8 lock here is mandatory.
    <span class="i">Locker locker;</span>
    <span class="i">RenewEvaluationContext();</span>
    <a id='1056' tid='1055', class="m">Context</a><a id='1058' tid='1057', class="m">::</a><a id='1060' tid='1059', class="m">Scope</a> <a id='1062' tid='1061', class="m">context_scope</a>(<a id='1064' tid='1063', class="m">evaluation_context_</a>);
    <a id='1006' tid='1005', class="m">for</a> (<a id='1008' tid='1007', class="m">int</a> <a id='1010' tid='1009', class="m">i</a> = <a id='1012' tid='1011', class="m">1</a>; <a id='1014' tid='1013', class="m">i</a> <a id='1016' tid='1015', class="m">&lt;</a> <a id='1018' tid='1017', class="m">argc</a>; <a id='1020' tid='1019', class="m">i</a><a id='1022' tid='1021', class="m">++</a>) {
      <a id='1024' tid='1023', class="m">char</a><a id='1026' tid='1025', class="m">*</a> <a id='1028' tid='1027', class="m">str</a> = <a id='1030' tid='1029', class="m">argv</a>[<a id='1032' tid='1031', class="m">i</a>];
      <a id='670' tid='669', class="m">if</a> (<a id='1034' tid='1033', class="m">strcmp</a>(<a id='1036' tid='1035', class="m">str</a>, <a id='1038' tid='1037', class="m">&quot;--preemption&quot;</a>) <a id='1040' tid='1039', class="m">==</a> <a id='1042' tid='1041', class="m">0</a>) {
        <a id='672' tid='671', class="m">use_preemption</a> <a id='674' tid='673', class="m">=</a> <a id='676' tid='675', class="m">true</a>;
      } <a id='678' tid='677', class="m">else</a> <a id='680' tid='679', class="m">if</a> (<a id='682' tid='681', class="m">strcmp</a>(<a id='684' tid='683', class="m">str</a>, <a id='686' tid='685', class="m">&quot;--no-preemption&quot;</a>) <a id='688' tid='687', class="m">==</a> <a id='690' tid='689', class="m">0</a>) {
        <a id='692' tid='691', class="m">use_preemption</a> <a id='694' tid='693', class="m">=</a> <a id='696' tid='695', class="m">false</a>;
      } <a id='698' tid='697', class="m">else</a> <a id='700' tid='699', class="m">if</a> (<a id='702' tid='701', class="m">strcmp</a>(<a id='704' tid='703', class="m">str</a>, <a id='706' tid='705', class="m">&quot;--preemption-interval&quot;</a>) <a id='708' tid='707', class="m">==</a> <a id='710' tid='709', class="m">0</a>) {
        <a id='712' tid='711', class="m">if</a> (<a id='714' tid='713', class="m">i</a> <a id='716' tid='715', class="m">+</a> <a id='718' tid='717', class="m">1</a> <a id='720' tid='719', class="m">&lt;</a> <a id='722' tid='721', class="m">argc</a>) {
          <a id='724' tid='723', class="m">char</a><a id='726' tid='725', class="m">*</a> <a id='728' tid='727', class="m">end</a> = <a id='730' tid='729', class="m">NULL</a>;
          <a id='732' tid='731', class="m">preemption_interval</a> <a id='734' tid='733', class="m">=</a> <a id='736' tid='735', class="m">strtol</a>(<a id='738' tid='737', class="m">argv</a>[<a id='740' tid='739', class="m">++</a><a id='742' tid='741', class="m">i</a>], <a id='744' tid='743', class="m">&</a><a id='746' tid='745', class="m">end</a>, <a id='748' tid='747', class="m">10</a>);  // NOLINT
          <a id='750' tid='749', class="m">if</a> (<a id='752' tid='751', class="m">preemption_interval</a> <a id='754' tid='753', class="m">&lt;=</a> <a id='756' tid='755', class="m">0</a> <a id='758' tid='757', class="m">||</a> <a id='760' tid='759', class="m">*</a><a id='762' tid='761', class="m">end</a> <a id='764' tid='763', class="m">!=</a> <a id='766' tid='765', class="m">&#39;\0&#39;</a> <a id='768' tid='767', class="m">||</a> <a id='770' tid='769', class="m">errno</a> <a id='772' tid='771', class="m">==</a> <a id='774' tid='773', class="m">ERANGE</a>) {
            <a id='776' tid='775', class="m">printf</a>(<a id='778' tid='777', class="m">&quot;Invalid value for --preemption-interval &#39;%s&#39;\n&quot;</a>, <a id='780' tid='779', class="m">argv</a>[<a id='782' tid='781', class="m">i</a>]);
            <a id='784' tid='783', class="m">return</a> <a id='786' tid='785', class="m">1</a>;
          }
        } <a id='788' tid='787', class="m">else</a> {
          <a id='790' tid='789', class="m">printf</a>(<a id='792' tid='791', class="m">&quot;Missing value for --preemption-interval\n&quot;</a>);
          <a id='794' tid='793', class="m">return</a> <a id='796' tid='795', class="m">1</a>;
        }
      } <a id='798' tid='797', class="m">else</a> <a id='800' tid='799', class="m">if</a> (<a id='802' tid='801', class="m">strcmp</a>(<a id='804' tid='803', class="m">str</a>, <a id='806' tid='805', class="m">&quot;-f&quot;</a>) <a id='808' tid='807', class="m">==</a> <a id='810' tid='809', class="m">0</a>) {
        // Ignore any -f flags for compatibility with other stand-alone
        // JavaScript engines.
        <a id='812' tid='811', class="m">continue</a>;
      } <a id='814' tid='813', class="m">else</a> <a id='816' tid='815', class="m">if</a> (<a id='818' tid='817', class="m">strncmp</a>(<a id='820' tid='819', class="m">str</a>, <a id='822' tid='821', class="m">&quot;--&quot;</a>, <a id='824' tid='823', class="m">2</a>) <a id='826' tid='825', class="m">==</a> <a id='828' tid='827', class="m">0</a>) {
        <a id='830' tid='829', class="m">printf</a>(<a id='832' tid='831', class="m">&quot;Warning: unknown flag %s.\nTry --help for options\n&quot;</a>, <a id='834' tid='833', class="m">str</a>);
      } <a id='836' tid='835', class="m">else</a> <a id='838' tid='837', class="m">if</a> (<a id='840' tid='839', class="m">strcmp</a>(<a id='842' tid='841', class="m">str</a>, <a id='844' tid='843', class="m">&quot;-e&quot;</a>) <a id='846' tid='845', class="m">==</a> <a id='848' tid='847', class="m">0</a> <a id='850' tid='849', class="m">&&</a> <a id='852' tid='851', class="m">i</a> <a id='854' tid='853', class="m">+</a> <a id='856' tid='855', class="m">1</a> <a id='858' tid='857', class="m">&lt;</a> <a id='860' tid='859', class="m">argc</a>) {
        // Execute argument given to -e option directly.
        <span class="i">v8::HandleScope handle_scope;</span>
        <a id='862' tid='861', class="m">v8</a><a id='864' tid='863', class="m">::</a><a id='866' tid='865', class="m">Handle</a>&lt;<a id='868' tid='867', class="m">v8</a><a id='870' tid='869', class="m">::</a><a id='872' tid='871', class="m">String</a>&gt; <a id='874' tid='873', class="m">file_name</a> = <a id='876' tid='875', class="m">v8</a><a id='878' tid='877', class="m">::</a><a id='880' tid='879', class="m">String</a><a id='882' tid='881', class="m">::</a><a id='884' tid='883', class="m">New</a>(<a id='886' tid='885', class="m">&quot;unnamed&quot;</a>);
        <a id='592' tid='591', class="m">v8</a><a id='594' tid='593', class="m">::</a><a id='596' tid='595', class="m">Handle</a>&lt;<a id='598' tid='597', class="m">v8</a><a id='600' tid='599', class="m">::</a><a id='602' tid='601', class="m">String</a>&gt; <a id='604' tid='603', class="m">source</a> = <a id='606' tid='605', class="m">v8</a><a id='608' tid='607', class="m">::</a><a id='610' tid='609', class="m">String</a><a id='612' tid='611', class="m">::</a><a id='614' tid='613', class="m">New</a><span class="i">(argv[++i])</span>;
        (<span class="i">*executed) = true;</span>
        <a id='492' tid='491', class="m">if</a> (<a id='494' tid='493', class="m">!</a><a id='496' tid='495', class="m">ExecuteString</a>(<a id='498' tid='497', class="m">source</a>, <a id='500' tid='499', class="m">file_name</a>, <a id='502' tid='501', class="m">false</a>, <a id='504' tid='503', class="m">true</a>)) {
          <a id='506' tid='505', class="m">OnExit</a>();
          <a id='508' tid='507', class="m">return</a> <a id='510' tid='509', class="m">1</a>;
        }
      } <a id='888' tid='887', class="m">else</a> <a id='890' tid='889', class="m">if</a> (<a id='892' tid='891', class="m">strcmp</a>(<a id='894' tid='893', class="m">str</a>, <a id='896' tid='895', class="m">&quot;-p&quot;</a>) <a id='898' tid='897', class="m">==</a> <a id='900' tid='899', class="m">0</a> <a id='902' tid='901', class="m">&&</a> <a id='904' tid='903', class="m">i</a> <a id='906' tid='905', class="m">+</a> <a id='908' tid='907', class="m">1</a> <a id='910' tid='909', class="m">&lt;</a> <a id='912' tid='911', class="m">argc</a>) {
        <span class="i">int size = 0;</span>
        <a id='914' tid='913', class="m">const</a> <a id='916' tid='915', class="m">char</a><a id='918' tid='917', class="m">*</a> <a id='920' tid='919', class="m">files</a> = <a id='922' tid='921', class="m">ReadChars</a>(<a id='924' tid='923', class="m">argv</a>[<a id='926' tid='925', class="m">++</a><a id='928' tid='927', class="m">i</a>], <a id='930' tid='929', class="m">&</a><a id='932' tid='931', class="m">size</a>);
        <a id='616' tid='615', class="m">if</a> (<a id='618' tid='617', class="m">files</a> <a id='620' tid='619', class="m">==</a> <a id='622' tid='621', class="m">NULL</a>) <a id='624' tid='623', class="m">return</a> <a id='626' tid='625', class="m">1</a>;
        <a id='512' tid='511', class="m">ShellThread</a><a id='514' tid='513', class="m">*</a> <a id='516' tid='515', class="m">thread</a> =
            <a id='518' tid='517', class="m">new</a> <a id='520' tid='519', class="m">ShellThread</a>(<a id='522' tid='521', class="m">threads</a>.<a id='524' tid='523', class="m">length</a>(),
                            <a id='526' tid='525', class="m">i</a><a id='528' tid='527', class="m">::</a><a id='530' tid='529', class="m">Vector</a>&lt;<a id='532' tid='531', class="m">const</a> <a id='534' tid='533', class="m">char</a>&gt;(<a id='536' tid='535', class="m">files</a>, <a id='538' tid='537', class="m">size</a>));
        <span class="i">thread-&gt;Start();</span>
        <span class="i">threads.Add(thread);</span>
        (<span class="i">*executed) = true;</span>
      } <a id='934' tid='933', class="m">else</a> {
        // Use all other arguments as names of files to load and run.
        <span class="i">HandleScope handle_scope;</span>
        <a id='936' tid='935', class="m">Handle</a>&lt;<a id='938' tid='937', class="m">String</a>&gt; <a id='940' tid='939', class="m">file_name</a> = <a id='942' tid='941', class="m">v8</a><a id='944' tid='943', class="m">::</a><a id='946' tid='945', class="m">String</a><a id='948' tid='947', class="m">::</a><a id='950' tid='949', class="m">New</a>(<a id='952' tid='951', class="m">str</a>);
        <a id='628' tid='627', class="m">Handle</a>&lt;<a id='630' tid='629', class="m">String</a>&gt; <a id='632' tid='631', class="m">source</a> = <a id='634' tid='633', class="m">ReadFile</a>(<a id='636' tid='635', class="m">str</a>);
        (<span class="i">*executed) = true;</span>
        <a id='540' tid='539', class="m">if</a> (<a id='542' tid='541', class="m">source</a>.<a id='544' tid='543', class="m">IsEmpty</a>()) {
          <a id='546' tid='545', class="m">printf</a>(<a id='548' tid='547', class="m">&quot;Error reading &#39;%s&#39;\n&quot;</a>, <a id='550' tid='549', class="m">str</a>);
          <a id='552' tid='551', class="m">return</a> <a id='554' tid='553', class="m">1</a>;
        }
        <a id='418' tid='417', class="m">if</a> (<a id='420' tid='419', class="m">!</a><a id='422' tid='421', class="m">ExecuteString</a>(<a id='424' tid='423', class="m">source</a>, <a id='426' tid='425', class="m">file_name</a>, <a id='428' tid='427', class="m">false</a>, <a id='430' tid='429', class="m">true</a>)) {
          <a id='432' tid='431', class="m">OnExit</a>();
          <a id='434' tid='433', class="m">return</a> <a id='436' tid='435', class="m">1</a>;
        }
      }
    }

    // Start preemption if threads have been created and preemption is enabled.
    <a id='648' tid='647', class="m">if</a> (<a id='650' tid='649', class="m">threads</a>.<a id='652' tid='651', class="m">length</a>() <a id='654' tid='653', class="m">&gt;</a> <a id='656' tid='655', class="m">0</a> <a id='658' tid='657', class="m">&&</a> <a id='660' tid='659', class="m">use_preemption</a>) {
      <a id='662' tid='661', class="m">Locker</a><a id='664' tid='663', class="m">::</a><a id='666' tid='665', class="m">StartPreemption</a>(<a id='668' tid='667', class="m">preemption_interval</a>);
    }
  }

  <a id='964' tid='963', class="m">for</a> (<a id='966' tid='965', class="m">int</a> <a id='968' tid='967', class="m">i</a> = <a id='970' tid='969', class="m">0</a>; <a id='972' tid='971', class="m">i</a> <a id='974' tid='973', class="m">&lt;</a> <a id='976' tid='975', class="m">threads</a>.<a id='978' tid='977', class="m">length</a>(); <a id='980' tid='979', class="m">i</a><a id='982' tid='981', class="m">++</a>) {
    <a id='984' tid='983', class="m">i</a><a id='986' tid='985', class="m">::</a><a id='988' tid='987', class="m">Thread</a><a id='990' tid='989', class="m">*</a> <a id='992' tid='991', class="m">thread</a> = <a id='994' tid='993', class="m">threads</a>[<a id='996' tid='995', class="m">i</a>];
    <a id='998' tid='997', class="m">thread</a>-&gt;<a id='1000' tid='999', class="m">Join</a>();
    <a id='1002' tid='1001', class="m">delete</a> <a id='1004' tid='1003', class="m">thread</a>;
  }
  <span class="i">OnExit();</span>
  <span class="i">return 0;</span>
 }


<span class="i">int Shell::Main(int argc, char* argv[]) {
  // Figure out if we&#39;re requested to stress the optimization
  // infrastructure by running tests multiple times and forcing
  // optimization in the last run.
  bool FLAG_stress_opt = false;
  bool FLAG_stress_deopt = false;
  bool FLAG_interactive_shell = false;
  bool FLAG_test_shell = false;
  bool script_executed = false;

  for (int i = 0; i &lt; argc; i++) {
    if (strcmp(argv[i], &quot;--stress-opt&quot;) == 0) {
      FLAG_stress_opt = true;
      argv[i] = NULL;
    } else if (strcmp(argv[i], &quot;--stress-deopt&quot;) == 0) {
      FLAG_stress_deopt = true;
      argv[i] = NULL;
    } else if (strcmp(argv[i], &quot;--noalways-opt&quot;) == 0) {
      // No support for stressing if we can&#39;t use --always-opt.
      FLAG_stress_opt = false;
      FLAG_stress_deopt = false;
    } else if (strcmp(argv[i], &quot;--shell&quot;) == 0) {
      FLAG_interactive_shell = true;
      argv[i] = NULL;
    } else if (strcmp(argv[i], &quot;--test&quot;) == 0) {
      FLAG_test_shell = true;
      argv[i] = NULL;
    }
  }

  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);

  Initialize(FLAG_test_shell);

  int result = 0;
  if (FLAG_stress_opt || FLAG_stress_deopt) {
    v8::Testing::SetStressRunType(
        FLAG_stress_opt ? v8::Testing::kStressTypeOpt
            : v8::Testing::kStressTypeDeopt);
    int stress_runs = v8::Testing::GetStressRuns();
    for (int i = 0; i &lt; stress_runs && result == 0; i++) {
      printf(&quot;============ Stress %d/%d ============\n&quot;, i + 1, stress_runs);
      v8::Testing::PrepareStressRun(i);
      result = RunMain(argc, argv, &script_executed);
    }
    printf(&quot;======== Full Deoptimization =======\n&quot;);
    v8::Testing::DeoptimizeAll();
  } else {
    result = RunMain(argc, argv, &script_executed);
  }

#ifdef ENABLE_DEBUGGER_SUPPORT
  // Run remote debugger if requested, but never on --test
  if (i::FLAG_remote_debugger && !FLAG_test_shell) {
    InstallUtilityScript();
    RunRemoteDebugger(i::FLAG_debugger_port);
    return 0;
  }
#endif

  // Run interactive shell if explicitly requested or if no script has been
  // executed, but never on --test
  if ((FLAG_interactive_shell || !script_executed) && !FLAG_test_shell) {
    InstallUtilityScript();
    RunShell();
  }

  v8::V8::Dispose();

  return result;
}</span>

 }  // namespace v8


<span class="i">#ifndef GOOGLE3</span>
<a id='4218' tid='4217', class="m">int</a> <a id='4220' tid='4219', class="m">main</a>(<a id='4222' tid='4221', class="m">int</a> <a id='4224' tid='4223', class="m">argc</a>, <a id='4226' tid='4225', class="m">char</a><a id='4228' tid='4227', class="m">*</a> <a id='4230' tid='4229', class="m">argv</a>[]) {
  <a id='4232' tid='4231', class="m">return</a> <a id='4234' tid='4233', class="m">v8</a><a id='4236' tid='4235', class="m">::</a><a id='4238' tid='4237', class="m">Shell</a><a id='4240' tid='4239', class="m">::</a><a id='4242' tid='4241', class="m">Main</a>(<a id='4244' tid='4243', class="m">argc</a>, <a id='4246' tid='4245', class="m">argv</a>);
}
<span class="i">#endif</span>

</pre>
</div>
</body>
</html>
